Пример #1
0
    void CastTeleport(FighterComponent casterFighter, PositionComponent positionComponent, string abDesc)
    {
        Vector2 moveDir = new Vector2(positionComponent.directionData.X, positionComponent.directionData.Y) * 2;

        //Vector2 curDest = new Vector2(positionComponent.moveData.X, positionComponent.moveData.Y) + moveDir;
        //if (MapManager.instance.CanMoveTo(new MoveData(curDest.x, curDest.y)) == false){
        //    // try normal move
        //    if MapManager.instance.CanMoveTo(new MoveData(curDest.x, curDest.y)) == false)
        //    {
        //        return;
        //    }
        //}

        //positionComponent.moveData = new MoveData(positionComponent.moveData.)


        // Caster takes 40% of its health
        float dmg = casterFighter.curHP * 0.40f;

        casterFighter.ReceiveDamage(dmg);
        MessageLog_Manager.NewMessage(abDesc, Color.green);

        MoveData destData = new MoveData(moveDir.x, moveDir.y);

        positionComponent.Move(destData, true);
    }
Пример #2
0
    public bool ReceiveDamage(float damage, bool byPoison = false)
    {
        // todo add damage received call back to resist/mitigate any damage
        curHP -= damage;
        curHP  = Mathf.Clamp(curHP, 0, 1000);

        if (OnHPChanged != null)
        {
            OnHPChanged(curHP, maxHP);
        }
        if (curHP <= 0)
        {
            if (byPoison == true)
            {
                if (thisEntity.isPlayer == true)
                {
                    MessageLog_Manager.NewMessage("The POISON CONSUMES YOU!", Color.red);
                }
                else
                {
                    MessageLog_Manager.NewMessage("The POISON CONSUMES " + thisEntity.Name, Color.red);
                }
            }

            Global.EntityDeath death = new Global.EntityDeath();
            death.deadEntity = thisEntity;
            death.FireEvent();
            return(true);
        }
        return(false);
    }
Пример #3
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);
    }
Пример #4
0
 void ClearLevel(bool restartingGame)
 {
     EntityManager.instance.StopPlayer();
     EntityManager.instance.ClearEnemies();
     EntityManager.instance.ClearItems();
     MessageLog_Manager.NewMessage("**************************************", Color.white);
     MessageLog_Manager.NewMessage("**************************************", Color.white);
     MessageLog_Manager.NewMessage("**************************************", Color.white);
     MapManager.instance.ClearTiles(restartingGame);
 }
Пример #5
0
    void CastBloodForLight(FighterComponent casterFighter, MoveData position, MoveData direction, string abDesc)
    {
        if (MapManager.instance.ClearDarkTile(new Vector2(position.X + direction.X, position.Y + direction.Y)) == false)
        {
            return;
        }

        // Caster takes 25% of its health
        float dmg = casterFighter.curHP * 0.25f;

        casterFighter.ReceiveDamage(dmg);
        MessageLog_Manager.NewMessage(abDesc, Color.green);
    }
Пример #6
0
    void LoadEntities(OnMapCreated data)
    {
        FXManager.instance.SpawnBackground(Vector2.zero, MapManager.instance.Map.mapWidth, MapManager.instance.Map.mapHeight);
        EntityManager.instance.SpawnPlayer(data.entranceWorldPosition);

        // No enemies on level 0

        if (curLevelPrototype.levelEnemies.Length <= 0)
        {
            // STORY MODE
            MessageLog_Manager.NewMessage("Might be best to go home now before it enters your lungs.", Color.white);
            MessageLog_Manager.NewMessage("But the stench of the Baron lingers in the air still... ", Color.magenta);
            MessageLog_Manager.NewMessage("You vowed to destroy him. Your quest is complete.", Color.white);
            MessageLog_Manager.NewMessage("a necro aristocrat that has dominated your homeland for over 200 years.", Color.white);
            MessageLog_Manager.NewMessage("Before you lies the slaughtered corpse of Baron Rasec", Color.cyan);



            return;
        }
        for (int i = 0; i < curLevelPrototype.levelEnemies.Length; i++)
        {
            // get a position for enemy needed
            Vector2[] enemyPositions = null;
            enemyPositions = mapManager.GetCleanPositions(curLevelPrototype.levelEnemies[i].count);
            Debug.Log(enemyPositions.Length + " returned positions");
            EntityManager.instance.SpawnEnemies(curLevelPrototype.levelEnemies[i].enemyPrototypeName, enemyPositions);
        }

        int itemCount = UnityEngine.Random.Range(0, 4);

        if (itemCount == 0)
        {
            return;
        }
        Vector2[] itemPositions = mapManager.GetCleanPositions(itemCount);
        int       maxItemIndex  = 2;

        if (difficultyLevel >= 2)
        {
            maxItemIndex = 4;
        }
        if (difficultyLevel >= 5)
        {
            maxItemIndex = itemNames.Length - 1;
        }
        for (int i = 0; i < itemPositions.Length; i++)
        {
            EntityManager.instance.SpawnItem(itemNames[UnityEngine.Random.Range(0, maxItemIndex + 1)], itemPositions[i]);
        }
    }
Пример #7
0
    private void NewMap()
    {
        // Chance to increase difficulty
        if (difficultyLevel <= 0)
        {
            difficultyLevel++;
        }
        else if (Level % 8 == 0)     // UnityEngine.Random.Range(1, 20) == 1
        {
            difficultyLevel++;
            MessageLog_Manager.NewMessage("Monsters become stronger...", Color.red);
            if (difficultyLevel > 10)
            {
                // Game win
                Debug.Log("You won the game!");
                Global.GameWin gameWin = new GameWin();
                gameWin.FireEvent();
                return;
            }
        }

        // TODO: PICK PROTOTYPE ACCORDING TO DIFFICULTY!
        if (difficultyLevel > 0)
        {
            List <LevelPrototype> potentialLevels = new List <LevelPrototype>();
            for (int i = 0; i < levelPrototypes.Length; i++)
            {
                if (levelPrototypes[i].difficultyLevel >= difficultyLevel - 1 &&
                    levelPrototypes[i].difficultyLevel <= difficultyLevel)
                {
                    potentialLevels.Add(levelPrototypes[i]);
                }
            }
            curLevelPrototype = potentialLevels[UnityEngine.Random.Range(0, potentialLevels.Count)];
        }


        if (curLevelPrototype.Name == string.Empty)
        {
            curLevelPrototype = levelPrototypes[1];
        }
        Debug.Log("New Map: diff=" + difficultyLevel + " curlvlProto name=" + curLevelPrototype.Name);

        mapManager.NewMap(Vector2.zero, Level, curLevelPrototype.darknessLevel);
    }
Пример #8
0
    public bool AddEquipment(ItemComponent itemComponent)
    {
        Entity itemEntity = itemComponent.thisEntity;

        if (itemComponent.itemType == ItemType.Weapon)
        {
            EntityComponent wComp = itemEntity.GetEntityComponent(ComponentID.Weapon);
            if (wComp == null)
            {
                return(false);
            }
            if (weapon != null)
            {
                DropCurWpn();
            }
            weapon = (WeaponComponent)wComp;
            Debug.Log("WEAPON added to equipment - " + itemComponent.itemName);
            MessageLog_Manager.NewMessage("You equip a " + itemComponent.itemName, Color.cyan);
            RenderSystem.instance.Render(itemComponent.itemName, wpnRenderer);
            return(true);
        }
        else if (itemComponent.itemType == ItemType.Armor)
        {
            EntityComponent aComp = itemEntity.GetEntityComponent(ComponentID.Armor);
            if (aComp == null)
            {
                return(false);
            }
            if (armor != null)
            {
                DropCurArmor();
            }
            armor = (ArmorComponent)aComp;
            Debug.Log("ARMOR added to equipment - " + itemComponent.itemName);
            MessageLog_Manager.NewMessage("You equip a " + itemComponent.itemName, Color.cyan);
            RenderSystem.instance.Render(itemComponent.itemName, armorRenderer);
            return(true);
        }
        return(false);
    }
Пример #9
0
    public bool AddItem(ItemComponent item)
    {
        //int emptyIndex = FindEmptyIndex();
        //if (emptyIndex < 0)
        //    return false;
        if (item.itemType == ItemType.Armor || item.itemType == ItemType.Weapon)
        {
            equipment.AddEquipment(item);
            return(true);
        }
        else
        {
            FighterComponent    fighterComponent = (FighterComponent)thisEntity.GetEntityComponent(ComponentID.Fighter);
            HealthDropComponent consumable       = (HealthDropComponent)item.thisEntity.GetEntityComponent(ComponentID.Consumable);
            fighterComponent.GainHealth(consumable.HealthGained);
            MessageLog_Manager.NewMessage("You consume " + item.itemName, Color.green);
            return(true);
        }

        //items[emptyIndex] = item;
        //Debug.Log(item.itemName + " added to inventory at index " + emptyIndex);
        //MessageLog_Manager.NewMessage("You pick up " + item.itemName, Color.yellow);
        //return true;
    }
Пример #10
0
    void OnXPChanged(XPData newXP)
    {
        if (xpData.TotalXP > 0)
        {
            int xpGain = newXP.TotalXP - xpData.TotalXP;
            MessageLog_Manager.NewMessage("You gain " + xpGain + " XP!", Color.yellow);

            if (newXP.CurXPLevel > xpData.CurXPLevel)
            {
                MessageLog_Manager.NewMessage("You are now level " + newXP.CurXPLevel, Color.yellow);
                // do level gain effect (gain max hp)
                fighter.IncreaseMaxHealth();

                if (xpData.CurXPLevel == 3)
                {
                    // gain teleport
                    abilityComponent.AddAbility(AbilityID.Teleport, true, "40% HP");
                }
            }
        }

        xpData = new XPData(newXP.TotalXP, newXP.CurXPLevel);
        UI_Manager.instance.HandlePlayerXPLevel(xpData.TotalXP, xpData.CurXPLevel);
    }