Browse Source

修改unit的管理器,去掉farmlanddic

master
wserver/wangdisen 3 years ago
parent
commit
1243345eaf
  1. 4
      Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs
  2. 4
      Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs
  3. 4
      Server/Hotfix/Demo/Farmland/Handler/C2M_GoFarmlandHarvestHandler.cs
  4. 4
      Server/Hotfix/Demo/Farmland/Handler/C2M_GoFarmlandPlantHandler.cs
  5. 2
      Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs
  6. 2
      Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs
  7. 15
      Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs
  8. 50
      Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs
  9. 2
      Unity/Codes/Model/Demo/Unit/Unit.cs

4
Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs

@ -11,8 +11,8 @@ namespace ET
try
{
People people;
Farmland farmland;
if (unit.FarmlandDic.TryGetValue(request.FarmlandId, out farmland))
Farmland farmland = unit.GetGrandChild<Farmland>(request.FarmlandId);
if (farmland!=null)
{
people = unit.GetComponent<PeopleComponent>().GetChild<People>(request.PeopleId);
if (people != null)

4
Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs

@ -10,8 +10,8 @@ namespace ET
try
{
People people;
Farmland farmland;
if (unit.FarmlandDic.TryGetValue(request.FarmlandId, out farmland))
Farmland farmland = unit.GetGrandChild<Farmland>(request.FarmlandId);
if (farmland!=null)
{
people = unit.GetComponent<PeopleComponent>().GetChild<People>(request.PeopleId);
if (people != null)

4
Server/Hotfix/Demo/Farmland/Handler/C2M_GoFarmlandHarvestHandler.cs

@ -18,8 +18,8 @@ namespace ET
}
else
{
Farmland farmland;
if (unit.FarmlandDic.TryGetValue(request.FarmlandId, out farmland))
Farmland farmland = unit.GetGrandChild<Farmland>(request.FarmlandId);
if (farmland!=null)
{
response.Error=FarmlandOperate.GoHarvest(unit,farmland, people);
}

4
Server/Hotfix/Demo/Farmland/Handler/C2M_GoFarmlandPlantHandler.cs

@ -18,8 +18,8 @@ namespace ET
}
else
{
Farmland farmland;
if (unit.FarmlandDic.TryGetValue(request.FarmlandId, out farmland))
Farmland farmland = unit.GetGrandChild<Farmland>(request.FarmlandId);
if (farmland!=null)
{
response.Error = FarmlandOperate.GoPlant(unit, farmland, people);
}

2
Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs

@ -4,7 +4,7 @@
{
public override void Destroy(Farmland self)
{
self.Parent.Parent.GetParent<Unit>().RemoveFarmland(self);
self.Parent.Parent.GetParent<Unit>().RemoveGrandChild(self.Id);
}
}

2
Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs

@ -179,7 +179,7 @@ namespace ET
{
var farmland = build.AddChild<Farmland>();
farmland.FarmlandState = FarmlandState.FARMLAND_STATE_FREE;
unit.FarmlandDic[farmland.Id] = farmland;
unit.AddGrandChild(farmland);
}
}

15
Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs

@ -19,13 +19,14 @@ namespace ET
farmland.PeopleId = people.Id;
return ErrorCode.ERR_Success;
}
public static int Plant(Unit unit, Farmland farmland, People people)
{
if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_SEED)
{
return ErrorCode.ERR_FarmlandNotFree;
}
farmland.Plant();
PeopleOperate.ChangeBehave(unit, people, farmland.Id, ConstBehaveType.BEHAVE_IDLE);
@ -45,9 +46,9 @@ namespace ET
farmland.PeopleId = people.Id;
return ErrorCode.ERR_Success;
}
public static int Harvest(Unit unit, Farmland farmland, People people)
{
if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_RIPE)
{
var storeNc = unit.GetComponent<StoreComponent>();
@ -61,10 +62,10 @@ namespace ET
farmland.Harvest();
return ErrorCode.ERR_Success;
}
PeopleOperate.ChangeBehave(unit, people, farmland.Id, ConstBehaveType.BEHAVE_IDLE);
return ErrorCode.ERR_FarmlandNotRipe;
}
public static (List<long>, List<int>) FarmlandSeed(Unit unit, List<long> farmlandIds, List<int> CropCfgIds)
@ -73,9 +74,12 @@ namespace ET
List<int> sucCropList = new List<int>();
for (int i = 0; i < farmlandIds.Count; i++)
{
Farmland farmland;
if (unit.FarmlandDic.TryGetValue(farmlandIds[i], out farmland))
Farmland farmland = unit.GetGrandChild<Farmland>(farmlandIds[i]);
if (farmland == null)
{
continue;
}
if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_FREE)
{
var cropCfg = CropConfigCategory.Instance.Get(CropCfgIds[i]);
@ -88,7 +92,6 @@ namespace ET
}
}
}
}
return (sucFarmlandList, sucCropList);
}

50
Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs

@ -7,7 +7,6 @@ namespace ET
{
public override void Awake(Unit self)
{
}
}
@ -75,7 +74,6 @@ namespace ET
public static void Update(this Unit self, long now)
{
#if SERVER
var synthesisComponent = self.GetComponent<SynthesisComponent>();
if (synthesisComponent != null)
{
@ -161,11 +159,11 @@ namespace ET
{
return;
}
self.Season = self.SeasonConfig.Id;
#if SERVER
UnitHelper.NofityUpdateValley(self, new List<int> { NumericType.Season }, new List<long> { self.Season });
#endif
}
public static void SetEmbattle(this Unit self, Dictionary<int, long> FighterDic)
@ -175,7 +173,6 @@ namespace ET
public static void EnterBattle(this Unit self, long enemyUnitId)
{
}
public static bool ExitBattle(this Unit self)
@ -196,7 +193,8 @@ namespace ET
var resConfig = ResourcesConfigCategory.Instance.Get(resConfigId);
for (int i = 0; i < resConfig.RebornCondition.Length; i++)
{
if (resConfig.RebornCondition[i] == (int)ResourcesRebornConditionEnum.SEASON &&resConfig.RebornConditionParameters[i]!=self.Season)
if (resConfig.RebornCondition[i] == (int) ResourcesRebornConditionEnum.SEASON &&
resConfig.RebornConditionParameters[i] != self.Season)
{
return false;
}
@ -210,7 +208,8 @@ namespace ET
var resConfig = ResourcesConfigCategory.Instance.Get(resConfigId);
for (int i = 0; i < resConfig.RebornCondition.Length; i++)
{
if (resConfig.RebornCondition[i] == (int)ResourcesRebornConditionEnum.SEASON &&resConfig.RebornConditionParameters[i]!=self.Season)
if (resConfig.RebornCondition[i] == (int) ResourcesRebornConditionEnum.SEASON &&
resConfig.RebornConditionParameters[i] != self.Season)
{
return false;
}
@ -225,21 +224,18 @@ namespace ET
self.GetComponent<BuildingComponent>()?.DurableReduce();
}
public static void AddFarmland(this Unit self,Farmland farmland)
{
self.FarmlandDic[farmland.Id] = farmland;
}
public static void RemoveFarmland(this Unit self, Farmland farmland)
{
self.FarmlandDic.Remove(farmland.Id);
}
public static void UpdateGameTime(this Unit self)
{
foreach (var v in self.FarmlandDic.Values)
//update farmland
foreach (var v in self.GrandChildren.Values)
{
if (v.GetType() == typeof (Farmland))
{
((Farmland) v).Update();
}
}
}
@ -258,17 +254,35 @@ namespace ET
{
return;
}
foreach (var v in self.GetComponent<BuildingComponent>().Children.Values)
{
foreach (var c in v.Children.Values)
{
if (c.GetType() == typeof (Farmland))
{
self.FarmlandDic[c.Id] = (Farmland) c;
self.AddGrandChild(c);
}
}
}
public static T GetGrandChild<T>(this Unit self, long id) where T : Entity
{
Entity child;
if (self.GrandChildren.TryGetValue(id, out child))
{
return (T) child;
}
return null;
}
public static void AddGrandChild<T>(this Unit self, T entity) where T : Entity
{
self.GrandChildren[entity.Id] = entity;
}
public static void RemoveGrandChild(this Unit self,long id)
{
self.GrandChildren.Remove(id);
}
}
}

2
Unity/Codes/Model/Demo/Unit/Unit.cs

@ -69,7 +69,7 @@ namespace ET
public long BattleId;
[BsonIgnore]
public Dictionary<long, Farmland> FarmlandDic = new Dictionary<long, Farmland>();
public Dictionary<long, Entity> GrandChildren = new Dictionary<long, Entity>();

Loading…
Cancel
Save