You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
4.1 KiB
106 lines
4.1 KiB
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
namespace ET |
|
{ |
|
public class ResourceComponentDestroySystem: DestroySystem<ResourcePointComponent> |
|
{ |
|
public override void Destroy(ResourcePointComponent self) |
|
{ |
|
} |
|
} |
|
|
|
[FriendClass(typeof (ResourcePoint))] |
|
public static class ResourcePointComponentSystem |
|
{ |
|
public static ResourcePoint CreateResourceByConfigId(this ResourcePointComponent self, Unit unit, int configId, float posX, float PosY, long id = 0) |
|
{ |
|
ResourcePoint res; |
|
if (id > 0) |
|
{ |
|
res = self.AddChildWithId<ResourcePoint>(id); |
|
} |
|
else |
|
{ |
|
res = self.AddChild<ResourcePoint>(); |
|
} |
|
|
|
res.ConfigId = configId; |
|
res.Position = new Vector2(posX, PosY); |
|
res.MatureState = ConstValue.Mature; |
|
var config = ResourcesPointConfigCategory.Instance.Get(configId); |
|
foreach (var relateId in config.RelatedResources) |
|
{ |
|
var resConfig = ResourcesConfigCategory.Instance.Get(relateId); |
|
if (unit.CanBorn(resConfig.Id)) |
|
{ |
|
List<ExtraOut> extraOuts = new List<ExtraOut>(); |
|
foreach (var v in resConfig.ExtraOut) |
|
{ |
|
var extraoutConfig = ExtraOutputConfigCategory.Instance.Get(v); |
|
if (extraoutConfig != null) |
|
{ |
|
var num = RandomHelper.RandomNumber(extraoutConfig.DropAmount[0], extraoutConfig.DropAmount[1]); |
|
extraOuts.Add(new ExtraOut(){CfgId = extraoutConfig.ItemId,GatherAmount = 0,MaxAmount = num}); |
|
} |
|
} |
|
res.ResAttriDic[relateId] = |
|
new ResourceAttri { ConfigId = relateId, GatherAmount = 0, MaxAmount = resConfig.OutAmount,ExtraOuts = extraOuts}; |
|
} |
|
} |
|
|
|
return res; |
|
} |
|
|
|
#if SERVER |
|
public static ResourcePoint CreateResourceByInitResItem(this ResourcePointComponent self, Unit unit,InitResourceItem item, long monsterGroupId) |
|
{ |
|
ResourcePoint res; |
|
res = self.AddChild<ResourcePoint>(); |
|
res.ConfigId = item.ConfigId; |
|
res.Position = new Vector2(item.PosX, item.PosY); |
|
res.MatureState = ConstValue.Mature; |
|
var config = ResourcesPointConfigCategory.Instance.Get(item.ConfigId); |
|
// res.MaxAmount = resConfig.OutAmount; |
|
// res.CurrAmount = 0; |
|
res.MonsterGroupId = monsterGroupId; |
|
foreach (var relateId in config.RelatedResources) |
|
{ |
|
var resConfig = ResourcesConfigCategory.Instance.Get(relateId); |
|
if (unit.CanBorn(resConfig.Id)) |
|
{ |
|
List<ExtraOut> extraOuts = new List<ExtraOut>(); |
|
foreach (var v in resConfig.ExtraOut) |
|
{ |
|
var extraoutConfig = ExtraOutputConfigCategory.Instance.Get(v); |
|
if (extraoutConfig != null) |
|
{ |
|
var num = RandomHelper.RandomNumber(extraoutConfig.DropAmount[0], extraoutConfig.DropAmount[1]); |
|
extraOuts.Add(new ExtraOut(){CfgId = extraoutConfig.ItemId,GatherAmount = 0,MaxAmount = num}); |
|
} |
|
} |
|
res.ResAttriDic[relateId] = |
|
new ResourceAttri { ConfigId = relateId, GatherAmount = 0, MaxAmount = resConfig.OutAmount,ExtraOuts = extraOuts}; |
|
} |
|
} |
|
|
|
return res; |
|
} |
|
#endif |
|
|
|
public static ResourcePoint GetResourceById(this ResourcePointComponent self, long id) |
|
{ |
|
foreach (var v in self.Children.Values) |
|
{ |
|
if (v.Id == id) |
|
{ |
|
return (ResourcePoint) v; |
|
} |
|
} |
|
|
|
return null; |
|
} |
|
|
|
|
|
} |
|
} |