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.
180 lines
5.8 KiB
180 lines
5.8 KiB
3 years ago
|
namespace ET
|
||
|
{
|
||
|
[FriendClass(typeof(Gather))]
|
||
|
[FriendClass(typeof(ResourcePoint))]
|
||
|
public static class GatherSystem
|
||
|
{
|
||
|
public static void FromMessage(this Gather self, GatherProto gatherProto)
|
||
|
{
|
||
|
self.Id = gatherProto.Id;
|
||
|
self.PeopleIdList = gatherProto.PeopleIdList;
|
||
|
self.PreparePeopleIdList = gatherProto.PreparePeopleIdList;
|
||
|
self.ResPointId = gatherProto.ResPointId;
|
||
|
self.ResConfigId = gatherProto.ResConfigId;
|
||
|
}
|
||
|
|
||
|
public static GatherProto ToMessage(this Gather self)
|
||
|
{
|
||
|
GatherProto proto = new GatherProto();
|
||
|
proto.Id = self.Id;
|
||
|
proto.PeopleIdList = self.PeopleIdList;
|
||
|
proto.PreparePeopleIdList = self.PreparePeopleIdList;
|
||
|
proto.ResConfigId = self.ResConfigId;
|
||
|
proto.ResPointId = self.ResPointId;
|
||
|
return proto;
|
||
|
}
|
||
|
|
||
|
public static bool StartGather(this Gather self, long peopleId)
|
||
|
{
|
||
|
if (self.PreparePeopleIdList.Contains(peopleId) && !self.PeopleIdList.Contains(peopleId))
|
||
|
{
|
||
|
self.PreparePeopleIdList.Remove(peopleId);
|
||
|
self.PeopleIdList.Add(peopleId);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static bool StopGather(this Gather self, long peopleId)
|
||
|
{
|
||
|
foreach (var v in self.PeopleIdList)
|
||
|
{
|
||
|
if (v == peopleId)
|
||
|
{
|
||
|
self.PeopleIdList.Remove(peopleId);
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static bool StopReadGather(this Gather self, long peopleId)
|
||
|
{
|
||
|
foreach (var v in self.PreparePeopleIdList)
|
||
|
{
|
||
|
if (v == peopleId)
|
||
|
{
|
||
|
self.PreparePeopleIdList.Remove(peopleId);
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static bool IsOver(this Gather self)
|
||
|
{
|
||
|
return self.PreparePeopleIdList.Count == 0 && self.PeopleIdList.Count == 0;
|
||
|
}
|
||
|
|
||
|
public static bool HavePeople(this Gather self, long peopleId)
|
||
|
{
|
||
|
return self.IsReadyPeople(peopleId) || self.IsGatherPeople(peopleId);
|
||
|
}
|
||
|
|
||
|
public static bool IsReadyPeople(this Gather self, long peopleId)
|
||
|
{
|
||
|
foreach (var v in self.PreparePeopleIdList)
|
||
|
{
|
||
|
if (v == peopleId)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static bool IsGatherPeople(this Gather self, long peopleId)
|
||
|
{
|
||
|
foreach (var v in self.PeopleIdList)
|
||
|
{
|
||
|
if (v == peopleId)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
#if SERVER
|
||
|
public static ResourceAttri Product(this Gather self, Unit unit, int tick)
|
||
|
{
|
||
|
self.GatherTime += tick;
|
||
|
ResourcePoint res = unit.GetComponent<ResourcePointComponent>().GetChild<ResourcePoint>(self.ResPointId);
|
||
|
ResourcesPointConfig pointConfig = res.Config;
|
||
|
|
||
|
ResourcesConfig config = ResourcesConfigCategory.Instance.Get(self.ResConfigId);
|
||
|
int amount = 0;
|
||
|
if (config.OutInterval == 0&&self.PeopleIdList.Count>0)
|
||
|
{
|
||
|
amount = config.OutAmount;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//每次的产量
|
||
|
amount = GatherOperate.GetPeopleProduceAmount(unit, self.PeopleIdList, config.BaseEfficient);
|
||
|
}
|
||
|
|
||
|
//资源扣除
|
||
|
if (res != null)
|
||
|
{
|
||
|
var (finish, product) = res.Product(config.Id,amount);
|
||
|
if (finish)
|
||
|
{
|
||
|
GatherOperate.FinishGather(unit, self.Id);
|
||
|
MessageHelper.SendToClient(unit, new M2C_NotifyGatherFinish() { GatherId = self.Id });
|
||
|
}
|
||
|
|
||
|
unit.GetComponent<StoreComponent>().Add(config.BaseOut, product);
|
||
|
}
|
||
|
|
||
|
//额外产出
|
||
|
if (config.ExtraOut > 0)
|
||
|
{
|
||
|
var dropConfig = DropGroupConfigCategory.Instance.Get(config.ExtraOut);
|
||
|
int index = 0;
|
||
|
if (dropConfig.ItemId.Length > 1)
|
||
|
{
|
||
|
index = RandomHelper.RandomByWeight(dropConfig.Weight);
|
||
|
}
|
||
|
|
||
|
//掉落数量
|
||
|
int dropAmount = RandomHelper.RandomNumber(dropConfig.DropAmount[index * 2], dropConfig.DropAmount[index * 2 + 1]);
|
||
|
unit.GetComponent<StoreComponent>().Add(dropConfig.ItemId[index], dropAmount);
|
||
|
}
|
||
|
|
||
|
//月圆之夜,
|
||
|
if (unit.IsMoonNight())
|
||
|
{
|
||
|
int rand = RandomHelper.RandInt32() % 100;
|
||
|
if (rand < config.OutProbability)
|
||
|
{
|
||
|
var dropConfig = DropGroupConfigCategory.Instance.Get(config.MoonnightOut);
|
||
|
int index = 0;
|
||
|
if (dropConfig.ItemId.Length > 1)
|
||
|
{
|
||
|
index = RandomHelper.RandomByWeight(dropConfig.Weight);
|
||
|
}
|
||
|
|
||
|
//掉落数量
|
||
|
int dropAmount = RandomHelper.RandomNumber(dropConfig.DropAmount[index * 2], dropConfig.DropAmount[index * 2 + 1]);
|
||
|
unit.GetComponent<StoreComponent>().Add(dropConfig.ItemId[index], dropAmount);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//露水
|
||
|
if (config.DewEachOut > 0 && unit.CanProductDew())
|
||
|
{
|
||
|
unit.GetComponent<StoreComponent>().Add(ConstValue.DewConfigId, config.DewEachOut);
|
||
|
}
|
||
|
|
||
|
return res.ResAttriDic[config.Id];
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
}
|
||
|
}
|