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.
85 lines
2.8 KiB
85 lines
2.8 KiB
3 years ago
|
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))
|
||
|
{
|
||
|
res.ResAttriDic[relateId] =
|
||
|
new ResourceAttri { ConfigId = relateId, GatherAmount = resConfig.OutAmount, MaxAmount = resConfig.OutAmount };
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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))
|
||
|
{
|
||
|
res.ResAttriDic[relateId] =
|
||
|
new ResourceAttri { ConfigId = relateId, GatherAmount = 0, MaxAmount = resConfig.OutAmount };
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|