// 销毁房间内所有对象 public virtual void Clear() { if (Map != null) { foreach (var u in AllUnits) { smm.Del(u.UID); u.Room = null; } Map.Clear(); } if (BuffRunner != null) { BuffRunner.Clear(); } if (TBRunner != null) { TBRunner.Clear(); } UsrsID = null; Players = null; frameSeqNo = 0; rand = null; idSeq = 0; }
public virtual void Init(string roomID, Vec2 mapSize, string mapID, string usr1, string usr2, UserInfo usrInfo1, UserInfo usrInfo2) { ID = roomID; var num = 3; UsrsID = new string[num]; UsrsID[0] = null; // 0 表示中立单位 UsrsID[1] = usr1; UsrsID[2] = usr2; UsrsInfo = new UserInfo[num]; UsrsInfo[0] = new UserInfo(); UsrsInfo[1] = usrInfo1; UsrsInfo[2] = usrInfo2; Players = new PlayerInfoInRoom[num]; Players[0] = null; Players[1] = new PlayerInfoInRoom(); Players[2] = new PlayerInfoInRoom(); Lv = LevelCreator.GetLevel(mapID); BuffRunner = new BuffRunner(); BuffRunner.Room = this; TBRunner = new TreasureBoxRunner(); TBRunner.Room = this; Map = new Map(mapSize, FrameInterval / 1000.0f); Map.Room = this; frameSeqNo = 0; smm.Clear(); }
public bool AddUnitAt(Unit building, Unit u) { if (!u.cfg.NoBody && !u.cfg.NoCard && !Map.CheckSpareSpace(u.cfg.IsAirUnit, (int)u.Pos.x, (int)u.Pos.y, u.cfg.SizeRadius)) { Vec2 newPt = Vec2.Zero; if (!Map.FindNearestSpareSpace(u.cfg.IsAirUnit, u.Pos, u.cfg.SizeRadius, 0, out newPt)) { return(false); } u.Pos = newPt; } u.Dir = u.ForwardDir; if (u.cfg.IsAirUnit) { Map.AddUnitInAir(u); } else { Map.AddUnitAt(u); } if (!u.IsNeutral) { // 人口数也要调整 var suppliment = u.cfg.Suppliment; AddResource(u.Player, "Suppliment", suppliment); } u.Room = this; var sm = u.CreateAI(); if (sm != null) { smm.Add(sm); } BuffRunner.OnUnitAdded(u); OnUnitAdded(building, u); return(true); }
Unit RemoveUnit(string uid) { smm.Del(uid); var u = GetUnit(uid); u.Room = null; Map.RemoveUnit(uid); u.Owner = null; // 人口数也要调整 if (!u.IsNeutral) { var suppliment = u.cfg.Suppliment; AddResource(u.Player, "Suppliment", -suppliment); } BuffRunner.OnUnitRemoved(u); OnUnitRemoved(u); return(u); }
public const int MaxFrameNum = 9000; // 最多 15 分钟一局 public virtual void MoveOneStep() { if (frameSeqNo >= MaxFrameNum) { BattleEnd(null); return; } frameSeqNo++; // 目标已死亡就从地图移除 foreach (var u in AllUnits) { if (u.Hp <= 0) { RemoveUnit(u.UID); foreach (var acc in u.Accessories.ToArray()) { RemoveUnit(acc.UID); } } } smm.OnTimeElapsed(FrameInterval); Map.DoOneStep(FrameInterval); // 宝箱和 buff if (TBRunner != null) { TBRunner.OnTimeElapsed(FrameInterval); } if (BuffRunner != null) { BuffRunner.OnTimeElapsed(FrameInterval); } }