/** * @brief 사거리 내에 있는 적을 공격 */ public void Attack() { int around = 0; if (GameMng.I.myTurn) { tilestate = gameObject.transform.parent.GetComponent <Tile>(); GameMng.I._hextile.FindDistancesTo(tilestate); DynamicObject obj = null; for (int i = 0; i < GameMng.I._hextile.cells.Length; i++) { if (GameMng.I._hextile.cells[i].Distance <= _attackdistance && GameMng.I._hextile.cells[i]._unitObj != null) { if (!GameMng.I._hextile.cells[i]._unitObj._uniqueNumber.Equals(NetworkMng.getInstance.uniqueNumber)) { Debug.Log("around unit: " + around); around++; NetworkMng.getInstance.SendMsg(string.Format("ATTACK:{0}:{1}:{2}:{3}:{4}", tilestate.PosX, tilestate.PosZ, GameMng.I._hextile.cells[i].PosX, GameMng.I._hextile.cells[i].PosZ, attack)); if (GameMng.I._hextile.cells[i]._unitObj != null) { obj = GameMng.I._hextile.cells[i]._unitObj; } _anim.SetTrigger("isAttacking"); obj._hp -= attack; if (obj._hp <= 0) { // 파괴 obj.DestroyMyself(); GameMng.I._hextile.GetCell(GameMng.I._hextile.cells[i].PosX, GameMng.I._hextile.cells[i].PosZ)._unitObj = null; GameMng.I._hextile.GetCell(GameMng.I._hextile.cells[i].PosX, GameMng.I._hextile.cells[i].PosZ)._builtObj = null; GameMng.I._hextile.TilecodeClear(GameMng.I._hextile.cells[i]); // TODO : 코드 값 원래 값으로 } obj = null; } } } } }
/** * @brief 유저 이름 변경 */ public void attack(int posX, int posY, int toX, int toY, int damage) { // 공격하는 대상이 공격하는 애니메이션을 취하도록 해줌 DynamicObject obj = null; if (_hextile.GetCell(posX, posY)._unitObj != null) { obj = _hextile.GetCell(posX, posY)._unitObj; } else if (_hextile.GetCell(posX, posY)._builtObj != null) { obj = _hextile.GetCell(posX, posY)._builtObj; } else { return; } if (_hextile.GetCell(posX, posY)._builtObj == null) { _UnitGM.reversalUnit(obj.transform, _hextile.GetCell(toX, toY).transform); } obj._anim.SetTrigger("isAttacking"); addActMessage(string.Format("{0}님이 공격했습니다.", obj._uniqueNumber), posX, posY); // 공격받는 대상의 HP 가 줄어들게 해줌 obj = null; if (_hextile.GetCell(toX, toY)._unitObj != null) { obj = _hextile.GetCell(toX, toY)._unitObj; } else if (_hextile.GetCell(toX, toY)._builtObj != null) { obj = _hextile.GetCell(toX, toY)._builtObj; } else { return; } if (_hextile.GetCell(toX, toY)._builtObj != null) { if (obj._uniqueNumber.Equals(NetworkMng.getInstance.uniqueNumber) && _hextile.GetCell(toX, toY)._code.Equals((int)BUILT.MINE)) { NetworkMng.getInstance.SendMsg(string.Format("PLUNDER:{0}:{1}:{2}:{3}", _hextile.GetCell(posX, posY)._unitObj._uniqueNumber, _hextile.GetCell(toX, toY)._builtObj._uniqueNumber, _gold * (damage * 2) / 100, 1)); } else { NetworkMng.getInstance.SendMsg(string.Format("PLUNDER:{0}:{1}:{2}:{3}", _hextile.GetCell(posX, posY)._unitObj._uniqueNumber, _hextile.GetCell(toX, toY)._builtObj._uniqueNumber, _food * (damage * 2) / 100, 1)); } } EffectSave(_hextile.GetCell(posX, posY)._unitObj._code, _hextile.GetCell(toX, toY).GetTileVec2.x, _hextile.GetCell(toX, toY).GetTileVec2.y); obj._hp -= damage; if (obj._hp <= 0) { // 파괴 obj.DestroyMyself(); //Destroy(obj.gameObject); _hextile.GetCell(toX, toY)._unitObj = null; _hextile.GetCell(toX, toY)._builtObj = null; _hextile.TilecodeClear(toX, toY); // TODO : 코드 값 원래 값으로 } }
/** * @brief 유저 이름 변경 */ public void attack(int posX, int posY, int toX, int toY, int damage) { // 공격하는 대상이 공격하는 애니메이션을 취하도록 해줌 DynamicObject obj = null; if (_hextile.GetCell(posX, posY)._unitObj != null) { obj = _hextile.GetCell(posX, posY)._unitObj; } else if (_hextile.GetCell(posX, posY)._builtObj != null) { obj = _hextile.GetCell(posX, posY)._builtObj; } else { return; } if (_hextile.GetCell(posX, posY)._builtObj == null) { _UnitGM.reversalUnit(obj.transform, _hextile.GetCell(toX, toY).transform); } obj._anim.SetTrigger("isAttacking"); addActMessage(string.Format("{0}님이 공격했습니다.", getUserName(obj._uniqueNumber)), posX, posY); addLogMessage(getUserName(obj._uniqueNumber), "공격을 시도했습니다."); // 공격받는 대상의 HP 가 줄어들게 해줌 obj = null; if (_hextile.GetCell(toX, toY)._unitObj != null) { obj = _hextile.GetCell(toX, toY)._unitObj; } else if (_hextile.GetCell(toX, toY)._builtObj != null) { obj = _hextile.GetCell(toX, toY)._builtObj; } else { return; } if (_hextile.GetCell(toX, toY)._builtObj != null && obj._uniqueNumber.Equals(NetworkMng.getInstance.uniqueNumber)) { if (_hextile.GetCell(toX, toY)._code.Equals((int)BUILT.MINE)) { NetworkMng.getInstance.SendMsg(string.Format("PLUNDER:{0}:{1}:{2}:{3}:{4}:{5}", _hextile.GetCell(posX, posY)._unitObj._uniqueNumber, _hextile.GetCell(toX, toY)._builtObj._uniqueNumber, _gold * (damage * 2) / 100, 0, toX, toY)); } else if (_hextile.GetCell(toX, toY)._code.Equals((int)BUILT.FARM)) { NetworkMng.getInstance.SendMsg(string.Format("PLUNDER:{0}:{1}:{2}:{3}:{4}:{5}", _hextile.GetCell(posX, posY)._unitObj._uniqueNumber, _hextile.GetCell(toX, toY)._builtObj._uniqueNumber, _food * (damage * 2) / 100, 1, toX, toY)); } } if (_hextile.GetCell(posX, posY)._unitObj._code == (int)UNIT.FOREST_WITCH_0 + (int)(NetworkMng.getInstance.myTribe) * 6 || _hextile.GetCell(posX, posY)._unitObj._code == (int)UNIT.FOREST_WITCH_1 + (int)(NetworkMng.getInstance.myTribe) * 6) { EffectSave(_hextile.GetCell(posX, posY)._unitObj._code, _hextile.GetCell(toX, toY).GetTileVec2.x, _hextile.GetCell(toX, toY).GetTileVec2.y); } obj._hp -= damage; if (obj._hp <= 0) { // 내 성이 파괴되었다면 서버에게 말해줌 if (obj._code.Equals(BUILT.CASTLE) && obj._uniqueNumber.Equals(NetworkMng.getInstance.uniqueNumber)) { NetworkMng.getInstance.SendMsg(string.Format("LOSE:{0}", NetworkMng.getInstance.uniqueNumber)); loseUI.SetActive(true); } // 파괴 obj.DestroyMyself(); //Destroy(obj.gameObject); _hextile.GetCell(toX, toY)._unitObj = null; _hextile.GetCell(toX, toY)._builtObj = null; _hextile.TilecodeClear(toX, toY); // TODO : 코드 값 원래 값으로 } }
private void OnGUI() { // { GUIStyle buttonStyle = GUI.skin.button;//("button"); if (buttonStyle != null) { buttonStyle.fontSize = 24; } } // { GUIStyle labelStyle = GUI.skin.label; if (labelStyle != null) { labelStyle.fontSize = 24; } } // Rect screenRect = new Rect(0.0f, 0.0f, Screen.width, Screen.height); GUILayout.BeginArea(screenRect); { GUILayout.BeginVertical(); { // インスタンス状況 string liveLabel = dynamicObject ? "<color=red>Alive</color>" : "<color=black>None</color>"; GUILayout.Label("DynamicObject=" + liveLabel); // ボタンの横幅 GUILayoutOption buttonMaxWidth = GUILayout.MaxWidth(512.0f); // 作成ボタン if (GUILayout.Button("Create", buttonMaxWidth)) { if (!dynamicObject) { GameObject gameObject = new GameObject("DynamicObject"); dynamicObject = gameObject.AddComponent <DynamicObject>(); dynamicObject.CreateCube(); } } // Sceneセクション GUILayout.Label("<color=green>Scene側から</color>"); // 破棄ボタン if (GUILayout.Button("Destroy", buttonMaxWidth)) { GameObject.Destroy(dynamicObject.gameObject); } // 即破棄ボタン if (GUILayout.Button("DestroyImmediate", buttonMaxWidth)) { GameObject.DestroyImmediate(dynamicObject.gameObject); } // DynamicObjectセクション GUILayout.Label("<color=navy>DynamicObject側から</color>"); // 破棄ボタン if (GUILayout.Button("Destroy", buttonMaxWidth)) { if (dynamicObject) { dynamicObject.DestroyMyself(); } } // 即破棄ボタン if (GUILayout.Button("DestroyImmediate", buttonMaxWidth)) { if (dynamicObject) { dynamicObject.DestroyImmediateMyself(); } } // 時間差破棄ボタン if (GUILayout.Button("DestroyDelay(1.0sec)", buttonMaxWidth)) { if (dynamicObject) { dynamicObject.DestroyMyselfDelay(1.0f); } } // Cubeだけ破棄ボタン if (GUILayout.Button("Destroy Cube", buttonMaxWidth)) { if (dynamicObject) { dynamicObject.DestroyCube(); } } } GUILayout.EndVertical(); } GUILayout.EndArea(); }