diff --git a/Config/WeatherConfigCategory.bytes b/Config/WeatherConfigCategory.bytes index a925540..cd64ce0 100644 Binary files a/Config/WeatherConfigCategory.bytes and b/Config/WeatherConfigCategory.bytes differ diff --git a/Excel/Json/c/WeatherConfig.txt b/Excel/Json/c/WeatherConfig.txt index a0e8ec4..70bec40 100644 --- a/Excel/Json/c/WeatherConfig.txt +++ b/Excel/Json/c/WeatherConfig.txt @@ -1,13 +1,13 @@ {"list":[ -{"_t":"WeatherConfig","_id":1,"Name":"大风","Disease":200,"Injury":0,"DurableDestroy":2,"LaborVariety":0,"Duration":[5,10],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[10,15],"ICON":"","Describe":""}, +{"_t":"WeatherConfig","_id":1,"Name":"大风","Disease":200,"Injury":0,"DurableDestroy":2,"LaborVariety":0,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[10,15],"ICON":"","Describe":""}, {"_t":"WeatherConfig","_id":2,"Name":"小雨","Disease":250,"Injury":0,"DurableDestroy":1,"LaborVariety":1,"Duration":[20,30],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, {"_t":"WeatherConfig","_id":3,"Name":"暴雨","Disease":300,"Injury":0,"DurableDestroy":3,"LaborVariety":2,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, -{"_t":"WeatherConfig","_id":4,"Name":"雷雨","Disease":350,"Injury":0,"DurableDestroy":5,"LaborVariety":3,"Duration":[5,10],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, -{"_t":"WeatherConfig","_id":5,"Name":"冰雹","Disease":300,"Injury":200,"DurableDestroy":15,"LaborVariety":3,"Duration":[3,5],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, +{"_t":"WeatherConfig","_id":4,"Name":"雷雨","Disease":350,"Injury":0,"DurableDestroy":5,"LaborVariety":3,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, +{"_t":"WeatherConfig","_id":5,"Name":"冰雹","Disease":300,"Injury":200,"DurableDestroy":15,"LaborVariety":3,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, {"_t":"WeatherConfig","_id":6,"Name":"高温","Disease":400,"Injury":0,"DurableDestroy":0,"LaborVariety":3,"Duration":[50,100],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[10,15],"ICON":"","Describe":""}, {"_t":"WeatherConfig","_id":7,"Name":"雪","Disease":400,"Injury":0,"DurableDestroy":5,"LaborVariety":3,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, -{"_t":"WeatherConfig","_id":8,"Name":"暴雪","Disease":500,"Injury":0,"DurableDestroy":10,"LaborVariety":5,"Duration":[5,10],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, -{"_t":"WeatherConfig","_id":9,"Name":"寒流","Disease":400,"Injury":0,"DurableDestroy":0,"LaborVariety":4,"Duration":[5,10],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[20,40],"ICON":"","Describe":"随机村民颤抖"}, -{"_t":"WeatherConfig","_id":10,"Name":"地震","Disease":0,"Injury":300,"DurableDestroy":30,"LaborVariety":10,"Duration":[3,5],"CD":[30],"WeaterEffect":"","SpecialEfficacyCD":[5,10],"ICON":"","Describe":""}, +{"_t":"WeatherConfig","_id":8,"Name":"暴雪","Disease":500,"Injury":0,"DurableDestroy":10,"LaborVariety":5,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, +{"_t":"WeatherConfig","_id":9,"Name":"寒流","Disease":400,"Injury":0,"DurableDestroy":0,"LaborVariety":4,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[20,40],"ICON":"","Describe":"随机村民颤抖"}, +{"_t":"WeatherConfig","_id":10,"Name":"地震","Disease":0,"Injury":300,"DurableDestroy":30,"LaborVariety":10,"Duration":[10,20],"CD":[30,30],"WeaterEffect":"","SpecialEfficacyCD":[5,10],"ICON":"","Describe":""}, {"_t":"WeatherConfig","_id":11,"Name":"流感","Disease":700,"Injury":0,"DurableDestroy":0,"LaborVariety":0,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[10,20],"ICON":"","Describe":"随机村民打喷嚏"}, ]} diff --git a/Excel/Json/s/WeatherConfig.txt b/Excel/Json/s/WeatherConfig.txt index a0e8ec4..70bec40 100644 --- a/Excel/Json/s/WeatherConfig.txt +++ b/Excel/Json/s/WeatherConfig.txt @@ -1,13 +1,13 @@ {"list":[ -{"_t":"WeatherConfig","_id":1,"Name":"大风","Disease":200,"Injury":0,"DurableDestroy":2,"LaborVariety":0,"Duration":[5,10],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[10,15],"ICON":"","Describe":""}, +{"_t":"WeatherConfig","_id":1,"Name":"大风","Disease":200,"Injury":0,"DurableDestroy":2,"LaborVariety":0,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[10,15],"ICON":"","Describe":""}, {"_t":"WeatherConfig","_id":2,"Name":"小雨","Disease":250,"Injury":0,"DurableDestroy":1,"LaborVariety":1,"Duration":[20,30],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, {"_t":"WeatherConfig","_id":3,"Name":"暴雨","Disease":300,"Injury":0,"DurableDestroy":3,"LaborVariety":2,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, -{"_t":"WeatherConfig","_id":4,"Name":"雷雨","Disease":350,"Injury":0,"DurableDestroy":5,"LaborVariety":3,"Duration":[5,10],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, -{"_t":"WeatherConfig","_id":5,"Name":"冰雹","Disease":300,"Injury":200,"DurableDestroy":15,"LaborVariety":3,"Duration":[3,5],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, +{"_t":"WeatherConfig","_id":4,"Name":"雷雨","Disease":350,"Injury":0,"DurableDestroy":5,"LaborVariety":3,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, +{"_t":"WeatherConfig","_id":5,"Name":"冰雹","Disease":300,"Injury":200,"DurableDestroy":15,"LaborVariety":3,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, {"_t":"WeatherConfig","_id":6,"Name":"高温","Disease":400,"Injury":0,"DurableDestroy":0,"LaborVariety":3,"Duration":[50,100],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[10,15],"ICON":"","Describe":""}, {"_t":"WeatherConfig","_id":7,"Name":"雪","Disease":400,"Injury":0,"DurableDestroy":5,"LaborVariety":3,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, -{"_t":"WeatherConfig","_id":8,"Name":"暴雪","Disease":500,"Injury":0,"DurableDestroy":10,"LaborVariety":5,"Duration":[5,10],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, -{"_t":"WeatherConfig","_id":9,"Name":"寒流","Disease":400,"Injury":0,"DurableDestroy":0,"LaborVariety":4,"Duration":[5,10],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[20,40],"ICON":"","Describe":"随机村民颤抖"}, -{"_t":"WeatherConfig","_id":10,"Name":"地震","Disease":0,"Injury":300,"DurableDestroy":30,"LaborVariety":10,"Duration":[3,5],"CD":[30],"WeaterEffect":"","SpecialEfficacyCD":[5,10],"ICON":"","Describe":""}, +{"_t":"WeatherConfig","_id":8,"Name":"暴雪","Disease":500,"Injury":0,"DurableDestroy":10,"LaborVariety":5,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[0],"ICON":"","Describe":""}, +{"_t":"WeatherConfig","_id":9,"Name":"寒流","Disease":400,"Injury":0,"DurableDestroy":0,"LaborVariety":4,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[20,40],"ICON":"","Describe":"随机村民颤抖"}, +{"_t":"WeatherConfig","_id":10,"Name":"地震","Disease":0,"Injury":300,"DurableDestroy":30,"LaborVariety":10,"Duration":[10,20],"CD":[30,30],"WeaterEffect":"","SpecialEfficacyCD":[5,10],"ICON":"","Describe":""}, {"_t":"WeatherConfig","_id":11,"Name":"流感","Disease":700,"Injury":0,"DurableDestroy":0,"LaborVariety":0,"Duration":[10,20],"CD":[2,3],"WeaterEffect":"","SpecialEfficacyCD":[10,20],"ICON":"","Describe":"随机村民打喷嚏"}, ]} diff --git a/Excel/WeatherConfig.xlsx b/Excel/WeatherConfig.xlsx index 24535df..764069e 100644 Binary files a/Excel/WeatherConfig.xlsx and b/Excel/WeatherConfig.xlsx differ diff --git a/Proto/OuterMessage.proto b/Proto/OuterMessage.proto index f93cef3..0b6130b 100644 --- a/Proto/OuterMessage.proto +++ b/Proto/OuterMessage.proto @@ -190,6 +190,7 @@ message UnitProto repeated string EventNames = 22; repeated int64 FighterList = 24; repeated MonsterGroupProto MonsterGroupList = 25; + WeatherProto Weather = 26; } message M2C_CreateUnits // IActorMessage @@ -1441,4 +1442,24 @@ message M2C_CabinHarvest // IActorLocationResponse int32 RpcId = 90; int32 Error = 91; string Message = 92; +} + +message WeatherProto +{ + int64 Id = 1; + int32 ConfigId = 2; + int32 State = 3; //1表示天气生效中 + +} + +message M2C_NtfWeatherStart // IActorMessage +{ + int32 WeatherCfgId = 1; +} + + +message M2C_NtfWeatherEnd // IActorMessage +{ + int32 WeatherCfgId = 1; + } \ No newline at end of file diff --git a/Server/Hotfix/Demo/Cabin/Handler/C2M_CabinSeedHandler.cs b/Server/Hotfix/Demo/Cabin/Handler/C2M_CabinSeedHandler.cs index befa4e6..c30ecc9 100644 --- a/Server/Hotfix/Demo/Cabin/Handler/C2M_CabinSeedHandler.cs +++ b/Server/Hotfix/Demo/Cabin/Handler/C2M_CabinSeedHandler.cs @@ -17,6 +17,10 @@ namespace ET res.Error = ErrorCode.ERR_PeopleNotFound; } + if (GameUtil.IsErrorSuc(res.Error) && farmland.FarmlandState != FarmlandState.FARMLAND_STATE_FREE) + { + res.Error = ErrorCode.ERR_FarmlandNotFree; + } var cabin = unit.GetGrandChild(farmland.CabinId); if (GameUtil.IsErrorSuc(res.Error) && cabin == null) { @@ -35,7 +39,7 @@ namespace ET if (GameUtil.IsErrorSuc(res.Error)) { - res.Error = FarmlandOperate.FarmlandSeed(unit, farmland, request.CropCfgId); + res.Error = CabinOperate.CabinSeed(unit, farmland, request.CropCfgId); } reply(); diff --git a/Server/Hotfix/Demo/Unit/UnitFactory.cs b/Server/Hotfix/Demo/Unit/UnitFactory.cs index c5c9884..a4dfb48 100644 --- a/Server/Hotfix/Demo/Unit/UnitFactory.cs +++ b/Server/Hotfix/Demo/Unit/UnitFactory.cs @@ -67,8 +67,8 @@ namespace ET InitStoreComponent(unit); InitMenuComponent(unit); InitPrescriptionComponent(unit); + InitWeather(unit); } - unit.InitPeopleNumberic(); return unit; @@ -194,6 +194,12 @@ namespace ET }*/ } + public static void InitWeather(Unit unit) + { + Weather weather = unit.AddChild(); + unit.WeatherId = weather.Id; + } + } } \ No newline at end of file diff --git a/Server/Hotfix/Demo/Unit/UnitHelper.cs b/Server/Hotfix/Demo/Unit/UnitHelper.cs index c02674f..2ffab73 100644 --- a/Server/Hotfix/Demo/Unit/UnitHelper.cs +++ b/Server/Hotfix/Demo/Unit/UnitHelper.cs @@ -158,5 +158,17 @@ namespace ET { MessageHelper.SendToClient(unit,new M2C_NotifyUpdateValley(){Ks = Ks,Vs = Vs}); } + + public static void NotifyWeatherStart(Unit unit, int cfgId) + { + MessageHelper.SendToClient(unit,new M2C_NtfWeatherStart(){WeatherCfgId = cfgId}); + } + + public static void NotifyWeatherEnd(Unit unit, int cfgId) + { + MessageHelper.SendToClient(unit,new M2C_NtfWeatherEnd(){WeatherCfgId = cfgId}); + } + + } } \ No newline at end of file diff --git a/Server/Hotfix/Server.Hotfix.csproj b/Server/Hotfix/Server.Hotfix.csproj index a870a99..370d748 100644 --- a/Server/Hotfix/Server.Hotfix.csproj +++ b/Server/Hotfix/Server.Hotfix.csproj @@ -160,6 +160,9 @@ Demo\Unit\UnitSystem.cs + + Demo\Weather\WeatherSystem.cs + Demo\WorldParam.cs diff --git a/Server/Model/Base/MongoRegister.cs b/Server/Model/Base/MongoRegister.cs index 15e38d7..7da3745 100644 --- a/Server/Model/Base/MongoRegister.cs +++ b/Server/Model/Base/MongoRegister.cs @@ -22,7 +22,7 @@ namespace ET BsonSerializer.RegisterSerializer(typeof(Quaternion), new StructBsonSerialize()); BsonSerializer.RegisterSerializer(typeof(ResourceAttri), new StructBsonSerialize()); BsonSerializer.RegisterSerializer(typeof(ExtraOut), new StructBsonSerialize()); - BsonSerializer.RegisterSerializer(typeof(WatherInfo), new StructBsonSerialize()); + BsonSerializer.RegisterSerializer(typeof(WeatherInfo), new StructBsonSerialize()); #elif ROBOT BsonSerializer.RegisterSerializer(typeof(Quaternion), new StructBsonSerialize()); BsonSerializer.RegisterSerializer(typeof(Vector3), new StructBsonSerialize()); diff --git a/Server/Model/Generate/Message/OuterMessage.cs b/Server/Model/Generate/Message/OuterMessage.cs index b9f2d4f..1614fc7 100644 --- a/Server/Model/Generate/Message/OuterMessage.cs +++ b/Server/Model/Generate/Message/OuterMessage.cs @@ -446,6 +446,9 @@ namespace ET [ProtoMember(25)] public List MonsterGroupList = new List(); + [ProtoMember(26)] + public WeatherProto Weather { get; set; } + } [Message(OuterOpcode.M2C_CreateUnits)] @@ -2999,4 +3002,37 @@ namespace ET } + [Message(OuterOpcode.WeatherProto)] + [ProtoContract] + public partial class WeatherProto: Object + { + [ProtoMember(1)] + public long Id { get; set; } + + [ProtoMember(2)] + public int ConfigId { get; set; } + + [ProtoMember(3)] + public int State { get; set; } + + } + + [Message(OuterOpcode.M2C_NtfWeatherStart)] + [ProtoContract] + public partial class M2C_NtfWeatherStart: Object, IActorMessage + { + [ProtoMember(1)] + public int WeatherCfgId { get; set; } + + } + + [Message(OuterOpcode.M2C_NtfWeatherEnd)] + [ProtoContract] + public partial class M2C_NtfWeatherEnd: Object, IActorMessage + { + [ProtoMember(1)] + public int WeatherCfgId { get; set; } + + } + } diff --git a/Server/Model/Generate/Message/OuterOpcode.cs b/Server/Model/Generate/Message/OuterOpcode.cs index 115d4f6..67abb88 100644 --- a/Server/Model/Generate/Message/OuterOpcode.cs +++ b/Server/Model/Generate/Message/OuterOpcode.cs @@ -179,5 +179,8 @@ namespace ET public const ushort M2C_CabinUpdateFarmlands = 10176; public const ushort C2M_CabinHarvest = 10177; public const ushort M2C_CabinHarvest = 10178; + public const ushort WeatherProto = 10179; + public const ushort M2C_NtfWeatherStart = 10180; + public const ushort M2C_NtfWeatherEnd = 10181; } } diff --git a/Unity/Assets/Bundles/Config/WeatherConfigCategory.bytes b/Unity/Assets/Bundles/Config/WeatherConfigCategory.bytes index a925540..cd64ce0 100644 Binary files a/Unity/Assets/Bundles/Config/WeatherConfigCategory.bytes and b/Unity/Assets/Bundles/Config/WeatherConfigCategory.bytes differ diff --git a/Unity/Codes/Hotfix/Demo/Unit/UnitFactory.cs b/Unity/Codes/Hotfix/Demo/Unit/UnitFactory.cs index 5a4a105..a5178c3 100644 --- a/Unity/Codes/Hotfix/Demo/Unit/UnitFactory.cs +++ b/Unity/Codes/Hotfix/Demo/Unit/UnitFactory.cs @@ -21,7 +21,6 @@ namespace ET unit.Day = unitProto.Day; unit.EventSeed = unitProto.EventSeed; unit.EventNames = unitProto.EventNames; - unit.SeasonConfig = SeasonConfigCategory.Instance.Get(unit.Season); for (int i = 0; i < unitProto.FighterList.Count / 2; i++) { diff --git a/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs b/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs index 4d0aff8..96f803c 100644 --- a/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs @@ -45,8 +45,11 @@ namespace ET } #endif + [FriendClass(typeof(People))] [FriendClass(typeof (Unit))] [FriendClass(typeof (Farmland))] + [FriendClass(typeof (Building))] + public static class UnitSystem { public static void AddTime(this Unit self, int tick) @@ -82,6 +85,16 @@ namespace ET synthesisComponent.Update(self, now); } + var dt = now - self.UpdateTimeSec; + dt = dt / 1000; + if (dt > 0) + { + self.GetChild(self.WeatherId).Update(self,(int)dt); + self.UpdateTimeSec += dt * 1000; + + } + + #endif } @@ -108,8 +121,13 @@ namespace ET UnitOperate.NightEvent(self, nightTime, time); //每天长大一岁 self.AddAge(); + //触发天气 + self.GetChild(self.WeatherId).Produce(self); + } self.GameTime = time; + self.GetChild(self.WeatherId).CheckStart(self,self.GameTime); + } } @@ -149,6 +167,7 @@ namespace ET self.SeasonConfig = SeasonConfigCategory.Instance.Get(self.Season); self.InitPeopleNumberic(); self.InitGrandChildren(); + self.UpdateTimeSec = self.UpdateTime; } public static void updateSeason(this Unit self) @@ -308,5 +327,19 @@ namespace ET { self.GrandChildren.Remove(id); } + + public static void OnWeatherEnd(this Unit self, int configId) + { + var config = WeatherConfigCategory.Instance.Get(configId); + foreach (var v in self.GetComponent().Children.Values) + { + ((People) v).Disease += config.Disease; + ((People) v).Injury += config.Injury; + } + foreach (var v in self.GetComponent().Children.Values) + { + ((Building) v).Durable -= config.DurableDestroy; + } + } } } \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Weather/Handler/M2C_NtfWeatherEndHandler.cs b/Unity/Codes/Hotfix/Demo/Weather/Handler/M2C_NtfWeatherEndHandler.cs new file mode 100644 index 0000000..47d64f7 --- /dev/null +++ b/Unity/Codes/Hotfix/Demo/Weather/Handler/M2C_NtfWeatherEndHandler.cs @@ -0,0 +1,13 @@ +namespace ET +{ + + + public class M2C_NtfWeatherEndHandler: AMHandler + { + protected override void Run(Session session, M2C_NtfWeatherEnd message) + { + + + } + } +} \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Weather/Handler/M2C_NtfWeatherStartHandler.cs b/Unity/Codes/Hotfix/Demo/Weather/Handler/M2C_NtfWeatherStartHandler.cs new file mode 100644 index 0000000..5d6674a --- /dev/null +++ b/Unity/Codes/Hotfix/Demo/Weather/Handler/M2C_NtfWeatherStartHandler.cs @@ -0,0 +1,10 @@ +namespace ET.Handler +{ + public class M2C_NtfWeatherStartHandler: AMHandler + { + protected override void Run(Session session, M2C_NtfWeatherStart message) + { + UnitComponent.unit.OnWeatherEnd(message.WeatherCfgId); + } + } +} \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Weather/WeatherSystem.cs b/Unity/Codes/Hotfix/Demo/Weather/WeatherSystem.cs new file mode 100644 index 0000000..1f6663c --- /dev/null +++ b/Unity/Codes/Hotfix/Demo/Weather/WeatherSystem.cs @@ -0,0 +1,125 @@ +using System.Collections.Generic; + +namespace ET +{ + [FriendClass(typeof(Weather))] + [FriendClass(typeof(Unit))] + public static class WeatherSystem + { + public static void FromMessage(this Weather self, WeatherProto weatherProto) + { + self.Id = weatherProto.Id; + self.ConfigId = weatherProto.ConfigId; + self.State = weatherProto.State; + } + + public static WeatherProto ToMessage(this Weather self) + { + WeatherProto weatherProto = new WeatherProto(); + weatherProto.Id = self.Id; + weatherProto.State = self.State; + return weatherProto; + } + + public static void Produce(this Weather self,Unit unit) + { + + if (self.Times >= 3 || self.ConfigId>0) + { + return; + } + + var seasonConfig = unit.GetSeasonConfig(); + var randomTimes = 0; + //随机季节 + while (self.ConfigId==0 && randomTimes>=seasonConfig.WeatherGroup.Length) + { + var index = RandomHelper.RandomByWeight(seasonConfig.Weights); + var weatherId = seasonConfig.WeatherGroup[index]; + randomTimes++; + WeatherInfo weatherInfo; + if (self.WeatherHistory.TryGetValue(weatherId,out weatherInfo)) + { + if (weatherInfo.Cd >= unit.Day - weatherInfo.StartDay) + { + self.ConfigId = weatherId; + } + } + else + { + self.ConfigId = weatherId; + } + } + + if (self.ConfigId == 0) + { + foreach (var v in seasonConfig.WeatherGroup) + { + WeatherInfo weatherInfo; + if (self.WeatherHistory.TryGetValue(v,out weatherInfo)) + { + if (weatherInfo.Cd >= unit.Day - weatherInfo.StartDay) + { + self.ConfigId = v; + break; + } + } + else + { + self.ConfigId = v; + break; + } + } + } + + if (self.ConfigId > 0) + { + self.Duration = RandomHelper.RandomNumber(self.Config.Duration[0], self.Config.Duration[1]+1); + var cd = RandomHelper.RandomNumber(self.Config.CD[0], self.Config.CD[1]+1); + self.StartTime = RandomHelper.RandomNumber(10, 16) * 100 + RandomHelper.RandomNumber(0, 60); + self.WeatherHistory[self.ConfigId] = new WeatherInfo() { ConfigId = self.ConfigId, Cd = cd, StartDay = unit.Day }; + + } + + + } + + public static void CheckStart(this Weather self,Unit unit,int gameTime) + { + if (self.ConfigId == 0) + { + return; + } + + if (self.StartTime < gameTime && self.State == 0) + { + self.State = 1; +#if SERVER + UnitHelper.NotifyWeatherStart(unit, self.ConfigId); + +#endif + } + + } + + public static void Update(this Weather self, Unit unit, int tick) + { + if (self.State == 0) + { + return; + } + + self.Duration -= tick; + if (self.Duration <= 0) + { + self.State = 0; + +#if SERVER + UnitHelper.NotifyWeatherEnd(unit, self.ConfigId); +#endif + self.ConfigId = 0; + } + + } + } +} \ No newline at end of file diff --git a/Unity/Codes/Model/Demo/People/People.cs b/Unity/Codes/Model/Demo/People/People.cs index 09a5e83..493bf20 100644 --- a/Unity/Codes/Model/Demo/People/People.cs +++ b/Unity/Codes/Model/Demo/People/People.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Options; diff --git a/Unity/Codes/Model/Demo/Unit/Unit.cs b/Unity/Codes/Model/Demo/Unit/Unit.cs index da921e0..fccf912 100644 --- a/Unity/Codes/Model/Demo/Unit/Unit.cs +++ b/Unity/Codes/Model/Demo/Unit/Unit.cs @@ -6,7 +6,7 @@ using UnityEngine; namespace ET { - [ChildType(typeof(Battle))] + [ChildType] #if SERVER public sealed class Unit: Entity, IAwake, IAddComponent, IGetComponent,IUpdate #else @@ -52,13 +52,14 @@ namespace ET public int EventSeed; public List EventNames; public int Hunger; //饥饿值 + public long WeatherId; [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] public Dictionary FighterDic=new Dictionary(); [BsonIgnore] - public long UpdateTime; + public long UpdateTime; //山谷时间 [BsonIgnore] public long UpdateValleyTime; @@ -72,6 +73,11 @@ namespace ET [BsonIgnore] public Dictionary GrandChildren = new Dictionary(); + [BsonIgnore] + public long UpdateTimeSec; + + + } diff --git a/Unity/Codes/Model/Demo/Weather/Weather.cs b/Unity/Codes/Model/Demo/Weather/Weather.cs index ee8c968..edcc30c 100644 --- a/Unity/Codes/Model/Demo/Weather/Weather.cs +++ b/Unity/Codes/Model/Demo/Weather/Weather.cs @@ -1,25 +1,29 @@ using System.Collections.Generic; +using MongoDB.Bson.Serialization.Attributes; namespace ET { - public struct WatherInfo + public struct WeatherInfo { public int ConfigId; public int Cd; - public int StartTime; //game day + public int StartDay; //game day } public class Weather:Entity,IAwake,ISerializeToEntity { public int ConfigId; public int Times; //当前季节触发次数 - public int Cd; public List SpringList; //春天列表 public List SummerList; public List AutumnList; public List WinterList; - public int StartTime;//开始时间,游戏时间 - public int RealStartTime; //实际时间 + public int StartTime;//开始时间(游戏时间) public int Duration; //持续 + public int State; //1表示天气影响中 + public Dictionary WeatherHistory = new Dictionary(); + + [BsonIgnore] + public WeatherConfig Config => WeatherConfigCategory.Instance.Get(this.ConfigId); diff --git a/Unity/Codes/Model/Generate/Message/OuterMessage.cs b/Unity/Codes/Model/Generate/Message/OuterMessage.cs index b9f2d4f..1614fc7 100644 --- a/Unity/Codes/Model/Generate/Message/OuterMessage.cs +++ b/Unity/Codes/Model/Generate/Message/OuterMessage.cs @@ -446,6 +446,9 @@ namespace ET [ProtoMember(25)] public List MonsterGroupList = new List(); + [ProtoMember(26)] + public WeatherProto Weather { get; set; } + } [Message(OuterOpcode.M2C_CreateUnits)] @@ -2999,4 +3002,37 @@ namespace ET } + [Message(OuterOpcode.WeatherProto)] + [ProtoContract] + public partial class WeatherProto: Object + { + [ProtoMember(1)] + public long Id { get; set; } + + [ProtoMember(2)] + public int ConfigId { get; set; } + + [ProtoMember(3)] + public int State { get; set; } + + } + + [Message(OuterOpcode.M2C_NtfWeatherStart)] + [ProtoContract] + public partial class M2C_NtfWeatherStart: Object, IActorMessage + { + [ProtoMember(1)] + public int WeatherCfgId { get; set; } + + } + + [Message(OuterOpcode.M2C_NtfWeatherEnd)] + [ProtoContract] + public partial class M2C_NtfWeatherEnd: Object, IActorMessage + { + [ProtoMember(1)] + public int WeatherCfgId { get; set; } + + } + } diff --git a/Unity/Codes/Model/Generate/Message/OuterOpcode.cs b/Unity/Codes/Model/Generate/Message/OuterOpcode.cs index 115d4f6..67abb88 100644 --- a/Unity/Codes/Model/Generate/Message/OuterOpcode.cs +++ b/Unity/Codes/Model/Generate/Message/OuterOpcode.cs @@ -179,5 +179,8 @@ namespace ET public const ushort M2C_CabinUpdateFarmlands = 10176; public const ushort C2M_CabinHarvest = 10177; public const ushort M2C_CabinHarvest = 10178; + public const ushort WeatherProto = 10179; + public const ushort M2C_NtfWeatherStart = 10180; + public const ushort M2C_NtfWeatherEnd = 10181; } }