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.
174 lines
5.5 KiB
174 lines
5.5 KiB
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof(Unit))] |
|
public static class UnitHelper |
|
{ |
|
public static UnitProto CreateUnitProto(Unit unit) |
|
{ |
|
UnitProto unitProto = new UnitProto(); |
|
|
|
unitProto.Id = unit.Id; |
|
unitProto.Food = unit.Food; |
|
unitProto.Water = unit.Water; |
|
unitProto.SilverTael = unit.SilverTael; |
|
unitProto.GoldIngot = unit.GoldIngot; |
|
unitProto.Season = unit.Season; |
|
unitProto.GameTime = unit.GameTime; |
|
unitProto.Prosperity = unit.Prosperity; |
|
unitProto.Name = unit.Name; |
|
unitProto.Scale = unit.Scale; |
|
unitProto.Day = unit.Day; |
|
unitProto.EventSeed = unit.EventSeed; |
|
unitProto.EventNames = unit.EventNames; |
|
BuildingComponent bc = unit.GetComponent<BuildingComponent>(); |
|
if (bc != null) |
|
{ |
|
foreach (var buildingInfo in bc.Children.Values) |
|
{ |
|
unitProto.Buildings.Add(((Building)buildingInfo).ToMessage()); |
|
} |
|
} |
|
|
|
PeopleComponent pc = unit.GetComponent<PeopleComponent>(); |
|
if (pc != null) |
|
{ |
|
foreach (var p in pc.Children.Values) |
|
{ |
|
unitProto.PeopleList.Add(((People)p).ToMessage()); |
|
} |
|
} |
|
|
|
|
|
|
|
ResourcePointComponent rc = unit.GetComponent<ResourcePointComponent>(); |
|
if (rc != null) |
|
{ |
|
foreach (var n in rc.Children.Values) |
|
{ |
|
unitProto.ResourceList.Add(((ResourcePoint)n).ToMessage()); |
|
|
|
} |
|
} |
|
|
|
StoreComponent sc = unit.GetComponent<StoreComponent>(); |
|
if (sc != null) |
|
{ |
|
foreach (var v in sc.Children.Values) |
|
{ |
|
unitProto.Store.Add(((Item)v).ToMessage()); |
|
} |
|
} |
|
|
|
GatherComponent gc = unit.GetComponent<GatherComponent>(); |
|
if (gc != null) |
|
{ |
|
foreach (var v in gc.Children.Values) |
|
{ |
|
unitProto.GatherList.Add(((Gather)v).ToMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
ConstructComponent constructComponent = unit.GetComponent<ConstructComponent>(); |
|
if (constructComponent != null) |
|
{ |
|
foreach (var v in constructComponent.Children.Values) |
|
{ |
|
unitProto.ConstructList.Add(((Construct)v).ToMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
SynthesisComponent synthesisComponent = unit.GetComponent<SynthesisComponent>(); |
|
if (synthesisComponent != null) |
|
{ |
|
foreach (var v in synthesisComponent.Children.Values) |
|
{ |
|
unitProto.SynthesisList.Add(((Synthesis)v).ToMessage()); |
|
} |
|
|
|
} |
|
|
|
MenuComponent menuComponent= unit.GetComponent<MenuComponent>(); |
|
if (menuComponent != null) |
|
{ |
|
foreach (var v in menuComponent.Children.Values) |
|
{ |
|
unitProto.MenuList.Add(((Menu)v).ToMessage()); |
|
} |
|
|
|
} |
|
|
|
foreach (var pair in unit.FighterDic) |
|
{ |
|
unitProto.FighterList.Add(pair.Key); |
|
unitProto.FighterList.Add(pair.Value); |
|
} |
|
|
|
MonsterGroupComponent monsterGroupComponent = unit.GetComponent<MonsterGroupComponent>(); |
|
if (monsterGroupComponent != null) |
|
{ |
|
foreach (var v in monsterGroupComponent.Children.Values) |
|
{ |
|
unitProto.MonsterGroupList.Add(((MonsterGroup)v).ToMessage()); |
|
} |
|
} |
|
|
|
|
|
return unitProto; |
|
} |
|
|
|
// 获取看见unit的玩家,主要用于广播 |
|
|
|
|
|
public static void NoticeUnitAdd(Unit unit, Unit sendUnit) |
|
{ |
|
M2C_CreateUnits createUnits = new M2C_CreateUnits(); |
|
createUnits.Units.Add(CreateUnitProto(sendUnit)); |
|
MessageHelper.SendToClient(unit, createUnits); |
|
} |
|
|
|
public static void NoticeUnitRemove(Unit unit, Unit sendUnit) |
|
{ |
|
M2C_RemoveUnits removeUnits = new M2C_RemoveUnits(); |
|
removeUnits.Units.Add(sendUnit.Id); |
|
MessageHelper.SendToClient(unit, removeUnits); |
|
} |
|
|
|
|
|
|
|
public static async ETTask InitUnit(Unit unit, bool isNew) |
|
{ |
|
//new player init |
|
if (isNew) |
|
{ |
|
|
|
} |
|
|
|
//unit.UpdateTime = TimeHelper.ServerNow()/1000; |
|
await ETTask.CompletedTask; |
|
} |
|
|
|
public static void NofityUpdateValley(Unit unit, List<int> Ks, List<long> Vs) |
|
{ |
|
MessageHelper.SendToClient(unit,new M2C_NotifyUpdateValley(){Ks = Ks,Vs = Vs}); |
|
} |
|
|
|
public static void NotifyWeatherStart(Unit unit, int cfgId) |
|
{ |
|
MessageHelper.SendToClient(unit,new M2C_NtfWeatherStart(){WeatherCfgId = cfgId}); |
|
} |
|
|
|
public static void NotifyWeatherEnd(Unit unit, int cfgId) |
|
{ |
|
MessageHelper.SendToClient(unit,new M2C_NtfWeatherEnd(){WeatherCfgId = cfgId}); |
|
} |
|
|
|
|
|
} |
|
} |