public void CancelConstructing() { if (animator != null) { animator.SetInteger("state", idle); } var root = transform.Find("Root"); if (mu.U.cfg.ReconstructTo != null) { FC.ForEach(mu.U.cfg.ReconstructTo, (i, t) => { var c = root.Find(t); if (c != null) { c.gameObject.SetActive(false); } }); } Destroy(scaffold.gameObject); scaffold = null; scaffoldUID = null; }
protected override void Sync() { BeginSync(); SyncLong(ref Time); SyncString(ref MapName); if (IsWrite) { W.Write(Messages.Count); FC.ForEach(Messages, (i, msg) => { W.Write(msg.Length); W.Write(msg); }); } else { Messages.Clear(); var count = R.ReadInt(); FC.For(count, (i) => { var dataLen = R.ReadInt(); var data = R.ReadBytes(dataLen); Messages.Add(data); }); } EndSync(); }
// 投放机 static StateMachine Carrier(Unit u) { var sm = new StateMachine(u.UID); var pts = new Vec2[] { Vec2.Zero, Vec2.Left, Vec2.Right, Vec2.Up, Vec2.Down }; var dropped = false; var ended = false; var moveImpl = MakeMove(u, u.MovePath, u.cfg.MaxVelocity); sm.NewState("moving").Run((st, te) => { ended = !moveImpl(te); u.Pos += u.PreferredVelocity; u.Dir = u.PreferredVelocity.Dir(); if (!dropped && u.MovePath.Count < 2) { dropped = true; FC.ForEach(u.UnitCosntructingWaitingList, (i, gu) => { var dropU = u.Room.AddNewUnit(null, gu, u.Pos + pts[i % pts.Length], u.Player); // 中立怪身上放宝箱 if (dropU != null && (gu == "NeutralMonster" || gu == "Blademaster" || gu == "Velkoz")) { dropU.OnDead += () => { string boxType = ""; switch (dropU.UnitType) { case "NeutralMonster": boxType = dropU.Room.TBRunner.RandomTreasureBoxType(1); break; case "Blademaster": boxType = dropU.Room.TBRunner.RandomTreasureBoxType(2); break; case "Velkoz": boxType = dropU.Room.TBRunner.RandomTreasureBoxType(3); break; } dropU.Room.TBRunner.CreateTreasureBox(boxType, dropU.Pos); }; } }); } }).AsDefault(); sm.NewState("dead").OnRunIn((st) => { u.Hp = 0; }).Run(null); // 到目的地就销毁 sm.Trans().From("moving").To("dead").When((st) => ended); return(sm); }
public void SaveAll() { using (var w = new BinaryWriter(new FileStream(SaveFile, FileMode.Create))) { w.Write(replays.Count); var buff = new WriteBuffer(); FC.ForEach(replays, (i, replay) => buff.Write(replay)); w.Write(buff.Data); w.Close(); } }
// 寻路 public List <int> FindPath(int fx, int fy, int tx, int ty, int maxSteps, TileType tileMask) { var path = new List <int>(); var nodes = pathFinder.Search(fx, fy, tx, ty, new KeyValuePair <int, int>(maxSteps, (int)tileMask), true); if (nodes != null) { nodes.RemoveFirst(); // remove the src node FC.ForEach(nodes, (i, n) => { path.Add((int)n.Pos.x); path.Add((int)n.Pos.y); }, () => path.Count < maxSteps * 2); } return(path); }
// 刷新卡牌选中状态 public void SetCardSels(int cnt) { FC.ForEach(CardsAvailableGroup, (i, c) => c.SelectedInPath = i < cnt); }
// 刷新暂存卡牌区域 public void RefreshCardsStarshed(List <BattleCard> cards = null) { FC.ForEach(CardsStashGroup, (i, c) => c.Card = i < cards.Count ? cards[i] : null); }
// 刷新战斗卡牌区域 public void RefreshCardsAvailable(List <BattleCard> cards = null) { FC.ForEach(CardsAvailableGroup, (i, c) => c.Card = i < cards.Count ? cards[i] : null); }
private void Awake() { FC.ForEach(CardsAvailableGroup, (i, c) => { c.Group = 0; c.IndexInGroup = i; }); FC.ForEach(CardsStashGroup, (i, c) => { c.Group = 1; c.IndexInGroup = i; }); }