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.
83 lines
2.4 KiB
83 lines
2.4 KiB
3 years ago
|
using System;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace ET
|
||
|
{
|
||
|
[FriendClass(typeof(Building))]
|
||
|
public static class BuildingComponentSystem
|
||
|
{
|
||
|
public static Building CreateBuilding(this BuildingComponent self, int ConfigId, float X, float Y, long id = 0)
|
||
|
{
|
||
|
Building building;
|
||
|
if (id == 0)
|
||
|
{
|
||
|
building = self.AddChild<Building>();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
building = self.AddChildWithId<Building>(id);
|
||
|
}
|
||
|
|
||
|
building.ConfigId = ConfigId;
|
||
|
building.Position = new Vector2(X, Y);
|
||
|
building.Durable = building.Config.Durable;
|
||
|
building.State = (int) BuildingState.Built;
|
||
|
return building;
|
||
|
}
|
||
|
|
||
|
public static bool CheckOutBuildingByIds(this BuildingComponent self, int[] StructureID)
|
||
|
{
|
||
|
bool hasBuilding = false;
|
||
|
foreach (var v in self.Children)
|
||
|
{
|
||
|
Building building = (Building) v.Value;
|
||
|
if (Array.IndexOf(StructureID, building.ConfigId) != -1 && building.State == (int) BuildingState.Built)
|
||
|
{
|
||
|
hasBuilding = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return hasBuilding;
|
||
|
}
|
||
|
|
||
|
public static bool CheckOutBuildingBySpecialType(this BuildingComponent self, int special)
|
||
|
{
|
||
|
bool hasBuilding = false;
|
||
|
foreach (var v in self.Children)
|
||
|
{
|
||
|
Building building = (Building) v.Value;
|
||
|
if (special == building.Config.Special && building.State == (int) BuildingState.Built)
|
||
|
{
|
||
|
hasBuilding = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return hasBuilding;
|
||
|
}
|
||
|
|
||
|
public static void DurableReduce(this BuildingComponent self)
|
||
|
{
|
||
|
foreach (var v in self.Children.Values)
|
||
|
{
|
||
|
((Building)v).DurableReduce();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static int GetBuildingNum(this BuildingComponent self, int configId)
|
||
|
{
|
||
|
int num = 0;
|
||
|
foreach (var keyValuePair in self.Children)
|
||
|
{
|
||
|
Building building = (Building)keyValuePair.Value;
|
||
|
if (building.ConfigId == configId)
|
||
|
{
|
||
|
num++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return num;
|
||
|
}
|
||
|
}
|
||
|
}
|