Esempio n. 1
0
 public CommandParams(UnitSO subject, UnitSO[] targets, ItemSO item, SkillSO skill)
 {
     this.subject = subject;
     this.targets = targets;
     this.item    = item;
     this.skill   = skill;
 }
Esempio n. 2
0
 void UpdateUnitSO(UnitSO unitSO)
 {
     if (unitSO)
     {
         unitSO.unitStatus = unitStatus;
     }
 }
Esempio n. 3
0
    public static float GetWeakness(StatusEffect type, UnitSO unit)
    {
        switch (type)
        {
        case STUN:
            return(unit.stunWeakness);

        case POISON:
            return(unit.poisonWeakness);

        case BURN:
            return(unit.burnWeakness);

        case FREEZE:
            return(unit.freezeWeakness);

        case CRYING:
            return(unit.cryingWeakness);

        case HUNGRY:
            return(unit.hungryWeakness);

        case FORGET:
            return(unit.forgetWeakness);
        }
        return(0);
    }
    public void OnStateEnter_ApplyDamageBurn()
    {
        RandomWrapper.test = true;

        UnitSO unit = TestUtil.CreateUnit();

        unit.finalMaxHP          = 100f;
        unit.currentHP           = 100f;
        unit.currentStatusEffect = new StatusEffect[1] {
            BURN
        };
        BattleSystem battleSystem = TestUtil.Create <BattleSystem>();

        battleSystem.allUnits = new UnitSO[1] {
            unit
        };
        State <BattleSystem> cleanUp = new ApplyBurnState(battleSystem);

        float atStart = unit.currentHP;

        cleanUp.OnStateExit();

        Assert.That(atStart > unit.currentHP);
        Assert.AreEqual(100f, atStart);
        Assert.AreEqual(97f, unit.currentHP);
    }
Esempio n. 5
0
    public float GetPower(UnitSO target)
    {
        float power = 0f;

        if (commandParams.GetSkill() != null)
        {
            if (commandParams.GetSkill().targeting.Equals(SkillTarget.SINGLE_ALLY) ||
                commandParams.GetSkill().targeting.Equals(SkillTarget.MULTIPLE_ALLIES))
            {
                power = commandParams.GetSkill().power;
            }
            else
            {
                power = -commandParams.GetSkill().power;
            }
        }
        else if (commandParams.GetItem().GetType() == typeof(ItemHealingSO))
        {
            power = ((ItemHealingSO)commandParams.GetItem()).power;
        }
        else if (commandParams.GetItem().GetType() == typeof(ItemOffensiveSO))
        {
            var   item     = (ItemOffensiveSO)commandParams.GetItem();
            float modifier = target.elementalWeakness[item.element];
            power = -item.power;
        }

        return(power);
    }
Esempio n. 6
0
    public void RemoveStatusEffectAwareWhenArrayItsNull()
    {
        UnitSO unit = TestUtil.CreateUnit();

        UnitUtil.RemoveStatusEffect(unit, StatusEffect.POISON);

        Assert.That(unit.currentStatusEffect.Length == 0);
    }
Esempio n. 7
0
    public static UnitSO[] GetUnitsFor(UnitSO subject, UnitSO[] units, bool offensive)
    {
        Controller subjectController  = subject.controller;
        Controller opposingController = subject.controller.Equals(PLAYER) ? AI : PLAYER;
        Controller targetController   = offensive? opposingController : subjectController;

        return(units.ToList().Where(it => it.controller.Equals(targetController)).ToArray());
    }
    public void ShouldClampHPMaxValue()
    {
        UnitSO unit      = TestUtil.CreateUnit();
        float  initialHP = unit.currentHP;

        var result = new ModifyHPUseCase(unit, 10).Execute();

        Assert.AreEqual(unit.currentHP, initialHP);
    }
Esempio n. 9
0
    void Tick()
    {
        if (npcNew && specialSO)
        {
            specialSO.dead = true;
            Destroy(npcNew);
        }
        if (objNew)
        {
            Destroy(objNew);
        }
        if (specialSO && specialSO.dead && specialSO.unitStatus == UnitStatus.People)
        {
            specialSO.unitStatus = UnitStatus.Empty;
        }
        lostSO.units.Remove(specialSO);

        // get random special
        //CopyUnitSO(RandomUnit(lostSO), specialSO);
        if (lostSO.units.Count != 0)
        {
            specialSO = RandomUnit(lostSO);
            showSO.units.Clear();
            showSO.units.Add(specialSO);
            specialSO.unitStatus = UnitStatus.Empty;

            // random and create npc movement;
            NPCBehavior npcBe = npc.GetComponent <NPCBehavior>();
            npcBe.unitSO = specialSO;
            RandomNewNPC(npcBe.npcSO);
            npcNew = Instantiate(npc);

            headIconUI.unitSO_test = specialSO;
            headIconUI.currentNPC  = npcNew;

            headIconUI.enabled = true;

            // create obj
            obj.GetComponent <ObjectBehavior>().unitSO   = specialSO;
            obj.GetComponent <ObjectBehavior>().mapPanel = mapPanel;
            mapPanel.GetComponent <MapPanel>().isChanged = true;

            objSpawner.GetComponent <CharacterItemsSpawner>().npcSO  = npcBe.npcSO;
            objSpawner.GetComponent <CharacterItemsSpawner>().soList = new UnitSO[] { specialSO };

            tempSpawner = Instantiate(objSpawner);
            GlobalControl.Instance.objPos = tempSpawner.GetComponent <CharacterItemsSpawner>().InstancedCharacterItemList[0].position;

            objTemplete.GetComponent <ObjectBehavior>().unitSO   = specialSO;
            objTemplete.GetComponent <ObjectBehavior>().mapPanel = mapPanel;
            mapPanel.GetComponent <MapPanel>().isChanged         = true;


            GameObject tempObj = Instantiate(objTemplete, GlobalControl.Instance.objPos, objTemplete.transform.rotation);
            Debug.Log(tempObj);
        }
    }
Esempio n. 10
0
 public CommandParams(UnitSO subject, UnitSO target, ItemSO item, SkillSO skill)
 {
     this.subject = subject;
     this.targets = new UnitSO[1] {
         target
     };
     this.item  = item;
     this.skill = skill;
 }
    public void ShouldChangeHP()
    {
        UnitSO unit      = TestUtil.CreateUnit();
        float  initialHP = unit.currentHP;

        var result = new ModifyHPUseCase(unit, -initialHP * 0.5f).Execute();

        Assert.AreEqual(unit.currentHP, initialHP - initialHP * 0.5f);
    }
Esempio n. 12
0
 public void SetUnit(UnitSO unit)
 {
     this.unit = unit;
     skillAnimation.SetUnitId(unit.unitId);
     damageLog.SetId(unit.unitId);
     image.sprite = unit.sprite;
     image.rectTransform.sizeDelta = new Vector2(unit.sprite.rect.width, unit.sprite.rect.height);
     statusEffects.Init(unit);
 }
Esempio n. 13
0
    public void AddNewPlayer(UnitSO unit, Vector3 location)
    {
        unit_list.Add(Instantiate(unit.unit_prefab, location, Quaternion.identity).GetComponent <Unit>());

        Unit new_unit = unit_list[unit_list.Count - 1];

        new_unit.encounter   = encounter;
        new_unit.name        = unit.unit_name + " (" + (unit_list.Count).ToString() + ")";
        new_unit.number.text = (unit_list.Count).ToString();
    }
Esempio n. 14
0
 void GimmeNames()
 {
     for (int i = 0; i < GameStatus.playerTeam.units.Length; i++)
     {
         UnitSO u = GameStatus.playerTeam.units[i];
         u           = Instantiate(u);
         u.unit.Name = RandomNames.RandomName();
         GameStatus.playerTeam.units[i] = u;
     }
 }
Esempio n. 15
0
    public void SetStatusEffectDontAddDuplicates()
    {
        UnitSO unit = TestUtil.CreateUnit();

        UnitUtil.SetStatusEffect(unit, StatusEffect.BURN);
        UnitUtil.SetStatusEffect(unit, StatusEffect.BURN);

        Assert.That(unit.currentStatusEffect.Length == 1);
        Assert.That(unit.currentStatusEffect.ToArray() [0].Equals(StatusEffect.BURN));
    }
    public void WhenHpIsZero_ApplyDeath()
    {
        UnitSO unit      = TestUtil.CreateUnit();
        float  initialHP = unit.currentHP;

        var result = new ModifyHPUseCase(unit, -2 * initialHP).Execute();

        Assert.AreEqual(unit.currentHP, 0);
        Assert.IsTrue(unit.currentStatusEffect.Contains(StatusEffect.DEATH));
    }
    private void Next(string targetId)
    {
        // Get the target
        UnitSO target = base.owner.allUnits.First(it => it.unitId.Equals(targetId));
        // Create wrapper object with the subject, target and skill
        CommandParams newParams = new CommandParams(commandParams.GetSubject(), target, commandParams.GetItem(), commandParams.GetSkill());

        // Go to the next state: select one target or select item
        base.owner.ChangeState(new AttackState(base.owner, newParams));
    }
Esempio n. 18
0
    public void SetStatusEffectAddValues()
    {
        UnitSO unit = TestUtil.CreateUnit();

        UnitUtil.SetStatusEffect(unit, StatusEffect.BURN);
        UnitUtil.SetStatusEffect(unit, StatusEffect.STUN);

        Assert.That(unit.currentStatusEffect.Length == 2);
        Assert.That(unit.currentStatusEffect.Contains(StatusEffect.BURN));
        Assert.That(unit.currentStatusEffect.Contains(StatusEffect.STUN));
    }
Esempio n. 19
0
    public static Entity SpawnUnit(float3 location, UnitSO unit, EntityCommandBuffer bcb)
    {
        Entity ent = bcb.Instantiate(unit.entityPrefab);

        bcb.SetComponent(ent, new Translation()
        {
            Value = location
        });

        return(ent);
    }
Esempio n. 20
0
    protected void AddNewPlayer(int unit_id, Vector3 location)
    {
        if (unit_id < 0 || unit_id >= unit_db.units.Length)
        {
            return;
        }

        UnitSO unit = unit_db.units[unit_id];

        raid_manager.AddNewPlayer(unit, location);
    }
Esempio n. 21
0
 public void SetUnit(UnitSO unit)
 {
     this.unit      = unit;
     nameText.text  = unit.unitName;
     levelText.text = "Lvl: " + unit.level;
     UpdateData(unit);
     skillAnimation.SetUnitId(unit.unitId);
     damageLog.SetId(unit.unitId);
     image.sprite = unit.sprite;
     image.rectTransform.sizeDelta = new Vector2(unit.sprite.rect.width, unit.sprite.rect.height);
     statusEffects.Init(unit);
 }
Esempio n. 22
0
    public void RemoveStatusEffectDeletesElement()
    {
        UnitSO unit = TestUtil.CreateUnit();

        UnitUtil.SetStatusEffect(unit, StatusEffect.BURN);
        UnitUtil.SetStatusEffect(unit, StatusEffect.STUN);

        UnitUtil.RemoveStatusEffect(unit, StatusEffect.BURN);

        Assert.That(unit.currentStatusEffect.Length == 1);
        Assert.That(!unit.currentStatusEffect.Contains(StatusEffect.BURN));
        Assert.That(unit.currentStatusEffect.Contains(StatusEffect.STUN));
    }
Esempio n. 23
0
    public void RemoveStatusEffectDoesNothingWhenTypeNotContained()
    {
        UnitSO unit = TestUtil.CreateUnit();

        UnitUtil.SetStatusEffect(unit, StatusEffect.BURN);
        UnitUtil.SetStatusEffect(unit, StatusEffect.STUN);

        UnitUtil.RemoveStatusEffect(unit, StatusEffect.POISON);

        Assert.That(unit.currentStatusEffect.Length == 2);
        Assert.That(unit.currentStatusEffect.Contains(StatusEffect.BURN));
        Assert.That(unit.currentStatusEffect.Contains(StatusEffect.STUN));
    }
Esempio n. 24
0
    public void ChargeTurnPoints_FunctionOfSpeed()
    {
        UnitSO unit = TestUtil.CreateUnit();

        UnitSO[] allUnits = new UnitSO[] { unit };
        unit.maxTurnCount     = 100f;
        unit.currentTurnCount = 0f;
        unit.finalSpeed       = 50;

        UnitUtil.ChargeTurnPointsAllUnits(allUnits, 1);

        Assert.AreEqual(50, unit.currentTurnCount);
    }
    public void WhenEnterState_RemoveStun()
    {
        UnitSO unit = TestUtil.CreateUnit();

        unit.currentStatusEffect = new StatusEffect[] { StatusEffect.STUN };
        BattleSystem battleSystem = TestUtil.CreateBattleSystem();

        UnitUpkeepState state = new UnitUpkeepState(battleSystem, unit);

        state.OnStateEnter();

        Assert.AreEqual(0, unit.currentStatusEffect.Length);
    }
Esempio n. 26
0
    public static void RemoveStatusEffect(UnitSO target, StatusEffect type)
    {
        if (target.currentStatusEffect == null)
        {
            target.currentStatusEffect = new StatusEffect[0];
            return;
        }
        int index  = Array.IndexOf(target.currentStatusEffect, type);
        var asList = target.currentStatusEffect.ToList();

        asList.Remove(type);
        target.currentStatusEffect = asList.ToArray();
    }
Esempio n. 27
0
    public override void Tick()
    {
        UnitUtil.ChargeTurnPointsAllUnits(base.owner.allUnits, Time.fixedDeltaTime);
        UnitSO tentativeActiveUnit = owner.GetActiveUnit();

        if (tentativeActiveUnit && tentativeActiveUnit.controller.Equals(PLAYER))
        {
            owner.ChangeState(new UnitUpkeepState(owner, tentativeActiveUnit));
        }
        else if (tentativeActiveUnit && tentativeActiveUnit.controller.Equals(AI))
        {
            owner.ChangeState(new AIState(owner, tentativeActiveUnit));
        }
    }
Esempio n. 28
0
    public override void Tick()
    {
        SkillSO randomSkill = RandomUtil.NextItem(activeUnit.skills);

        UnitSO[] randomTargets = new UnitSO[1] {
            pickRandomPlayerTarget()
        };
        switch (randomSkill.targeting)
        {
        case SINGLE_OPPONENT:
            randomTargets = new UnitSO[1] {
                pickRandomPlayerTarget()
            };
            break;

        case SINGLE_ALLY:
            randomTargets = new UnitSO[1] {
                activeUnit
            };
            break;

        case SELF:
            randomTargets = new UnitSO[1] {
                activeUnit
            };
            break;

        case MULTIPLE_ALLIES:
            randomTargets = UnitUtil.GetAliveFriends(base.owner.allUnits, AI);
            break;

        case MULTIPLE_OPPONENTS:
            randomTargets = UnitUtil.GetAliveOpponents(base.owner.allUnits, AI);
            break;

        default:
            throw new System.Exception("Exhaust enum at AIState.Tick()");
        }


        CommandParams commandParams = new CommandParams(
            activeUnit,
            randomTargets,
            null,
            randomSkill
            );

        base.owner.ChangeState(new AttackState(base.owner, commandParams));
    }
Esempio n. 29
0
    public void GivenElementalResistance_DoLessDamage()
    {
        UnitSO target = TestUtil.CreateUnit();

        target.elementalWeakness[Element.NORMAL] = 50;
        var cp = new CommandParams(
            TestUtil.CreateUnit(),
            target,
            null,
            TestUtil.CreateDamageSkill()
            );
        float result = new DamageUseCase(cp).Execute();

        Assert.AreEqual(23f, result);
    }
Esempio n. 30
0
 public void ClickOnUnitCreationButton(Enums.UnitName _unit)
 {
     //Debug.Log("1 : Clic on button :" + _unit.ToString());
     for (int i = 0; i < ((UnitBuilderSO)activeBuilding.building).droppableUnits.Length; i++)
     {
         if (((UnitBuilderSO)activeBuilding.building).droppableUnits[i].unitName == _unit)
         {
             //Debug.Log("2 : " + _unit.ToString() + " asked");
             UnitSO unitRequesting = Instantiate(((UnitBuilderSO)activeBuilding.building).droppableUnits[i]);
             activeBuilding.unitsInCreationRequest.Add(unitRequesting);
             //Debug.Log("2' : " + _unit.ToString() + " added in requesting queue");
             break;
         }
     }
 }