コード例 #1
0
    /// <summary>
    /// Handle entity combat.
    /// Return true if combat resulted in defender's death
    /// and attacker is allowed to move unto that tile.
    /// </summary>
    /// <param name="attacker"></param>
    /// <param name="defender"></param>
    /// <returns></returns>
    private bool DoCombat(FighterComponent attacker, FighterComponent defender)
    {
        int attackPower = attacker.GetAttackPower();
        // Debug.Log("Attacker attacks with power " + attackPower);
        //Debug.Log("Defender defends with power " + defender.GetDefensePower());
        //if (attacker.thisEntity.isPlayer == true)
        //{
        //    MessageLog_Manager.NewMessage("You attack the " + defender.thisEntity.Name + " with " + attackPower + " attack!", Color.red);
        //}
        int damage = attackPower - defender.GetDefensePower();

        //Debug.Log("After defense mitigation... damage is " + damage);

        if (damage > 0)
        {
            if (defender.thisEntity.isPlayer == true)
            {
                cameraShaker.AddTrauma(5.2f, 2.8f);
                MessageLog_Manager.NewMessage(attacker.thisEntity.Name + " hits you for " + damage.ToString() + "!", Color.white);
            }
            else
            {
                MessageLog_Manager.NewMessage("You hit the " + defender.thisEntity.Name + " for " + damage.ToString() + "!", Color.red);
            }
        }
        else
        {
            if (attacker.thisEntity.isPlayer == true)
            {
                MessageLog_Manager.NewMessage(defender.thisEntity.Name + "'s defense absorb your attack!", Color.white);
            }
            else
            {
                MessageLog_Manager.NewMessage("Your defenses absorb the attack!", Color.white);
            }
        }

        bool result = defender.ReceiveDamage(damage);

        if (result == true)
        {
            if (attacker.thisEntity.isPlayer == true)
            {
                MessageLog_Manager.NewMessage(defender.thisEntity.Name + " DIES!", Color.red);
                // Gain xp for kill
                XPComponent    xPComponent = (XPComponent)attacker.thisEntity.GetEntityComponent(ComponentID.XP);
                EnemyComponent enemy       = (EnemyComponent)defender.thisEntity.GetEntityComponent(ComponentID.AI);
                XPSystem.instance.DoXPGainAction(xPComponent.xpData, enemy.enemyLevel);
            }
            else
            {
                MessageLog_Manager.NewMessage(attacker.thisEntity.Name + " KILLS YOU!", Color.red);
            }
        }

        return(result);
    }
コード例 #2
0
    private void Update()
    {
        if (inputState == InputState.Off)
        {
            return;
        }
        Vector2 inputV2 = Vector2.zero;

        if (Input.GetButtonDown("DiagTopLeft"))
        {
            inputV2 = Vector2.up + Vector2.left;
        }
        else if (Input.GetButtonDown("DiagTopRight"))
        {
            inputV2 = Vector2.up + Vector2.right;
        }
        else if (Input.GetButtonDown("DiagBottomRight"))
        {
            inputV2 = Vector2.down + Vector2.right;
        }
        else if (Input.GetButtonDown("DiagBottomLeft"))
        {
            inputV2 = Vector2.down + Vector2.left;
        }
        else
        {
            inputV2 = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        }


        if (inputV2 != lastV2)
        {
            lastV2 = inputV2;
            if (inputV2 == Vector2.zero)
            {
                return;
            }
            if (OnMoveInput != null)
            {
                OnMoveInput(new MoveData(inputV2.x, inputV2.y));
            }
        }

        if (dynamicKeyActions.Count > 0)
        {
            for (int i = 0; i < dynamicKeyActions.Count; i++)
            {
                if (Input.GetKeyDown(dynamicKeyActions[i].dynamicKey))
                {
                    dynamicKeyActions[i].action();
                }
            }
        }


        if (canFindTile == false)
        {
            return;
        }
        mousePos = Vector2Int.FloorToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition));
        if (mousePos != lastMousePos)
        {
            lastMousePos = mousePos;
            infoUI.Clear();
            MapTile tile = mapManager.Map.GetTile(mousePos.x, mousePos.y);
            if (tile == null)
            {
                infoUI.DeActivate();
                return;
            }
            if (tile.tileType == TileType.Darkness)
            {
                infoUI.Activate();

                infoUI.UpdateTexts(new Message[] { new Message("Poison", Color.magenta), new Message("100%", Color.red), new Message("Lethal!", Color.red) });
                infoUI.UpdatePosition(mousePos + Vector2.left * 2, canvas);
                return;
            }
            if (tile.tileType == TileType.SemiDark)
            {
                infoUI.Activate();

                infoUI.UpdateTexts(new Message[] { new Message("Poison", Color.magenta), new Message("50%", Color.yellow), new Message("Dangerous!", Color.yellow) });
                infoUI.UpdatePosition(mousePos + Vector2.left * 2, canvas);
                return;
            }

            if (tile.entities.Count <= 0)
            {
                infoUI.DeActivate();
                return;
            }
            else
            {
                Message[] info = new Message[3];
                if (tile.entities[0].entityType == EntityType.Unit)
                {
                    FighterComponent fighter = (FighterComponent)tile.entities[0].GetEntityComponent(ComponentID.Fighter);
                    info[0] = new Message(fighter.thisEntity.Name, Color.white);
                    info[1] = new Message(fighter.GetAttackPower().ToString(), Color.red);
                    info[2] = new Message(fighter.GetDefensePower().ToString(), Color.cyan);
                }
                else if (tile.entities[0].entityType == EntityType.Item)
                {
                    ItemComponent item = (ItemComponent)tile.entities[0].GetEntityComponent(ComponentID.Item);
                    info[0] = new Message(item.itemName, Color.white);
                    if (item.itemType == ItemType.Weapon)
                    {
                        WeaponComponent wpn = (WeaponComponent)tile.entities[0].GetEntityComponent(ComponentID.Weapon);
                        info[1] = new Message(wpn.weaponAttackStats.AttackPower.ToString(), Color.red);
                        info[2] = new Message(wpn.weaponAttackStats.DefensePower.ToString(), Color.cyan);
                    }
                    else if (item.itemType == ItemType.Armor)
                    {
                        ArmorComponent armor = (ArmorComponent)tile.entities[0].GetEntityComponent(ComponentID.Armor);
                        info[1] = new Message(armor.armorAttackStats.AttackPower.ToString(), Color.red);
                        info[2] = new Message(armor.armorAttackStats.DefensePower.ToString(), Color.cyan);
                    }
                    else
                    {
                        HealthDropComponent consumable = (HealthDropComponent)tile.entities[0].GetEntityComponent(ComponentID.Consumable);
                        info[1] = new Message(consumable.HealthGained.ToString(), Color.cyan);
                    }
                }
                infoUI.Activate();
                infoUI.UpdateTexts(info);
                infoUI.UpdatePosition(mousePos + Vector2.left * 2, canvas);
            }
        }
    }