void RghtClickedOnGameObject(GameObject obj) { if (_choosed) { var from = _choosedObj.GetComponent <GameUnit>(); if (from == null || !from.IsMy()) { return; } var to = obj.GetComponent <GameEntity>(); if (to == null) { return; } if (!GroupUtil.isCreatureGroup(from.Group)) { return; } if (!FieldOfView.IsVisible(to) && !GroupUtil.IsGround(to.Group)) { ClickedOnSpace(); return; } Vector3Int f; if (from.MovingTo != null) { f = from.MovingTo.Index; } else { f = from.CurrentPos; f.z--; } //Cant move ? if (from.UpgradedStats.MoveSpeed <= 0f) { SimpleOrderManager.CancelOrders(from); ErrorBar_HTML.SetupError("This unit can`t move!"); return; } //Attack var t = to.CurrentPos; var buildingCheck = false; if (ChunkUtil.IsAnyEntity(from.ChunkNumber, ChunkUtil.GetUpper(t))) { var underGround = ChunkManager.CurrentChunk.GetGameObjectByIndex(ChunkUtil.GetUpper(t)); var underEnt = underGround.GetComponent <GameEntity>(); if (SecondaryGroundLvL.isSecondaryGroup(underEnt.Group)) { buildingCheck = true; } if (!GroupUtil.IsGround(underEnt.Group) && underEnt.Owner != PlayersManager.GetMyPlayer()) { var underP = underEnt.CurrentPos; underP.z++; if (!ChunkManager.CurrentChunk.IsMapPos(underP) || !ChunkUtil.IsAnyEntity(from.ChunkNumber, ChunkUtil.GetUpper(underEnt.CurrentPos))) { if (from.UpgradedStats.Dmg > 0) { SimpleOrderManager.AttackToIndex(from, t); } else if (from.UpgradedStats.Dmg == 0) { ErrorBar_HTML.SetupError("This unit can`t attack!"); } return; } } } //Cancel or Move if ((ChunkUtil.IsAnyEntity(from.ChunkNumber, ChunkUtil.GetUpper(t)) || !PathCalcManager.IsReaching(f, t)) && !buildingCheck) { ErrorBar_HTML.SetupError("Can`t reach that place!"); SimpleOrderManager.CancelOrders(from); } else if (ChunkUtil.IsCanStayHere(from.ChunkNumber, t) || buildingCheck) { SimpleOrderManager.MoveToIndex(from, t); } } else { var clicked = obj.GetComponent <GameEntity>(); if (clicked == null) { return; } var pos = clicked.CurrentPos; if (FlagManager.IsFlagAtPos(pos)) { FlagManager.RemoveFlag(pos); } else { FlagManager.SetupFlag(pos); } } }
public override void KillSelf() { if (Destroyed) { return; } var chunk = ChunkManager.GetChunkByNum(ChunkNumber); chunk.SetIndex(CurrentPos, -1); chunk.RemoveObject(CurrentPos); if (pickUped != null) { ItemEvents.OnDeathDropItem(pickUped, this); } ClickManager.RemoveChosing(gameObject); GameMoveManager.CancelAllOrders(this); if (GroupUtil.isCreatureGroup(Group)) { GameOrderManager.RemoveMarks(this); //SimpleOrderManager.CancelOrders(this); if (MovingPath != null) { MovingPath.Clear(); } } if (SecondaryGroundLvL.isSecondaryGroup(Group)) { SecondaryGroundLvL.RemovePos(ChunkNumber, CurrentPos); } if (FlagManager.IsFlagAtPos(CurrentPos)) { FlagManager.RemoveFlag(CurrentPos); } ProgressUnitBar.RemoveProgressBar(this); CreatureGroupManager.RemoveEntFromGroup(this); BuildingsGroupManager.RemoveBuildingFromGroup(this); RemoveAbilities(); if (research != null) { var sameBuilds = BuildingsGroupManager.GetAllInChunkWithName(ChunkNumber, OriginalName); if (sameBuilds.Count == 0) { Owner.RemoveResearch(research); } } Coloring.RecolorObject(ChunkUtil.GetDovvner(CurrentPos)); Owner.foodCount -= foodCost; Owner.foodMax -= foodGive; if (gameObject != null) { Destroy(gameObject); } Destroyed = true; }