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.
58 lines
1.9 KiB
58 lines
1.9 KiB
3 years ago
|
namespace ET
|
||
|
{
|
||
|
[FriendClass(typeof(MonsterGroup))]
|
||
|
[FriendClass(typeof(ResourcePoint))]
|
||
|
public static class MonsterGroupComponentSystem
|
||
|
{
|
||
|
#if SERVER
|
||
|
public static MonsterGroup CreateMonsterGroup(this MonsterGroupComponent self, InitResourceItem item)
|
||
|
{
|
||
|
if (item.MonsterGroupConfigId > 0)
|
||
|
{
|
||
|
var monsterGroup = self.AddChild<MonsterGroup,int>(item.MonsterGroupConfigId);
|
||
|
monsterGroup.RefreshType = item.RefreshType;
|
||
|
monsterGroup.RefreshParm = item.RefreshParameter;
|
||
|
monsterGroup.X = item.PosX;
|
||
|
monsterGroup.Y = item.PosY;
|
||
|
monsterGroup.Seed = RandomHelper.RandomNumber(100000000,999999999);
|
||
|
return monsterGroup;
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
public static MonsterGroup GetMonsterGroupById(this MonsterGroupComponent self, long id)
|
||
|
{
|
||
|
foreach (var v in self.Children.Values)
|
||
|
{
|
||
|
if (v.Id == id)
|
||
|
{
|
||
|
return (MonsterGroup) v;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
public static void KillMonsterGroup(this MonsterGroupComponent self, Unit unit, long id)
|
||
|
{
|
||
|
var monsterGroup = self.GetMonsterGroupById(id);
|
||
|
if (monsterGroup != null)
|
||
|
{
|
||
|
var res = unit.GetOrAddComponent<ResourcePointComponent>().GetResourceById(monsterGroup.ResId);
|
||
|
if (res != null)
|
||
|
{
|
||
|
Log.Info("KillMonsterGroup");
|
||
|
res.MonsterGroupId = 0;
|
||
|
#if !SERVER
|
||
|
// 抛出资源上的怪被清除的事件
|
||
|
Game.EventSystem.Publish(new EventType.ResourceMonsterKilled() { Unit = unit, ResourceId = monsterGroup.ResId});
|
||
|
#endif
|
||
|
}
|
||
|
monsterGroup.Dispose();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|