public static Creature fromJSONObject(JSONObject json)
    {
        int           creatureId   = (int)json.GetField("creatureId").n;
        string        creatureName = json.GetField("creatureName").str;
        CreatureStats baseStats    = CreatureStats.fromJSONObject(json.GetField("baseStats"));
        //TODO deserialize Abilities
        Ability        ability = null;
        HashSet <Move> moves   = new HashSet <Move>();

        foreach (JSONObject moveName in json.GetField("moves").list)
        {
            string n = moveName.str;
            moves.Add(MoveLibrary.get(n));
        }
        FocalPoints         focalPoints    = FocalPoints.fromJSONObject(json.GetField("focalPoints"));
        CreatureForm        baseForm       = CreatureForm.fromJSONObject(json.GetField("baseForm"));
        List <CreatureForm> availableForms = new List <CreatureForm>();

        foreach (JSONObject formJSON in json.GetField("availableForms").list)
        {
            CreatureForm creatureForm = CreatureForm.fromJSONObject(formJSON);
            availableForms.Add(CreatureForm.fromJSONObject(formJSON));
        }
        Creature result = new Creature(creatureId, creatureName, moves, focalPoints, ability, baseStats, baseForm, availableForms);

        return(result);
    }
 public Focus(FocalPoints focalPoints, Watchers watcher)
 {
     this.currentFocus   = 30;
     this.focusPerUpdate = 10;
     endTurnFocus        = false;
     updateCurrentThreshold();
     this.focalPoints = focalPoints;
     subscribe(watcher.turnPhaseWatcher);
 }
        public void testCreatureDeserialization()
        {
            LibraryLoader.loadMoveLibrary();

            string     creatureJSONString = "{\"creatureId\":1,\n\"creatureName\":\"\",\n\"baseStats\":[10,10,10,10],\n\"abilityId\":1,\n\"moves\":[\"Strike\",\"Slam\"],\n\"focalPoints\":[\n{\n\"description\":\"Small boost to strength\",\n\"statMods\":{\n\"STR\":[5,1]\n}\n},\n{\n\"description\":\"Small boost to armor\",\n\"statMods\":{\n\"ARM\":[5, 1]\n}\n},\n{\n\"description\":\"Additional armor scaling\",\n\"statMods\":{\n\"ARM\":[0, 1.1]\n}\n},\n{\n\"description\":\"Small boost to speed\",\n\"statMods\":{\n\"SPD\":[5, 1]\n}\n}\n],\n\"baseForm\":{\n\"creatureTypes\":[\"Vital\"],\n\"abilityId\":1,\n\"revealAction\":null\n},\n\"availableForms\":[\n{\n\"creatureTypes\":[\"Flame\"],\n\"statMods\":{\n\"STR\":[5, 1],\n\"ARM\":[0, 1],\n\"SPD\":[0, 1]\n},\n\"moveId\":null,\n\"abilityId\":1,\n\"revealAction\":null\n}\n]\n}";
            JSONObject creatureJSON       = JSONObject.Create(creatureJSONString);

            Creature actual = Creature.fromJSONObject(creatureJSON);

            HashSet <Move> expectedMoves = new HashSet <Move>();

            expectedMoves.Add(MoveLibrary.get("Strike"));
            expectedMoves.Add(MoveLibrary.get("Slam"));
            StatModifier           sm1 = new StatModifier(5, 1);
            StatModifier           sm2 = new StatModifier(0, 1.1);
            StatModifier           sm3 = new StatModifier(0, 1);
            FocusPoint             fp1 = new FocusPoint(null, null, makeListOfStatMod(StatName.STR, sm1), "Small boost to strength");
            FocusPoint             fp2 = new FocusPoint(null, null, makeListOfStatMod(StatName.ARM, sm1), "Small boost to armor");
            FocusPoint             fp3 = new FocusPoint(null, null, makeListOfStatMod(StatName.ARM, sm2), "Additional armor scaling");
            FocusPoint             fp4 = new FocusPoint(null, null, makeListOfStatMod(StatName.SPD, sm1), "Small boost to speed");
            FocalPoints            expectedFocalPoints = new FocalPoints(fp1, fp2, fp3, fp4);
            CreatureStats          expectedBaseStats   = new CreatureStats(10, 10, 10, 10);
            Ability                expectedAbility     = null;
            HashSet <CreatureType> expectedTypesBase   = new HashSet <CreatureType>();

            expectedTypesBase.Add(CreatureType.VITAL);
            CreatureForm expectedBaseForm = new CreatureForm(expectedTypesBase, null, null);

            HashSet <CreatureType> expectedTypesForm = new HashSet <CreatureType>();

            expectedTypesForm.Add(CreatureType.FLAME);

            List <Pair <StatName, StatModifier> > expectedFormMods = new List <Pair <StatName, StatModifier> >();

            expectedFormMods.Add(new Pair <StatName, StatModifier>(StatName.STR, sm1));
            expectedFormMods.Add(new Pair <StatName, StatModifier>(StatName.ARM, sm3));
            expectedFormMods.Add(new Pair <StatName, StatModifier>(StatName.SPD, sm3));
            CreatureForm expectedAltForm = new CreatureForm(expectedTypesForm, expectedFormMods, null, null, null);

            //"availableForms\":[\n{\n\"creatureTypes\":[\"Flame\"],\n\"statMods\":{\n\"STR\":[5, 1],\n\"ARM\":[0, 1],\n\"SPD\":[0, 1]\n},\n\"moveId\":null,\n\"abilityId\":1,\n\"revealAction\":null\n}\n]

            List <CreatureForm> expectedAvailableForms = new List <CreatureForm>();

            expectedAvailableForms.Add(expectedAltForm);

            foreach (Pair <StatName, StatModifier> pair in expectedAltForm.statMods)
            {
                Debug.Log("Alt form mod: " + pair.ToString());
            }

            Creature expected = new Creature(1, "", expectedMoves, expectedFocalPoints, expectedAbility, expectedBaseStats, expectedBaseForm, expectedAvailableForms);

            Assert.That(expected.Equals(actual));
        }
 public Creature(int creatureId, string creatureName, HashSet <Move> moveset, FocalPoints focalPoints, Ability creatureAbility, CreatureStats baseStats, CreatureForm baseForm, List <CreatureForm> availableForms)
 {
     this.creatureId      = creatureId;
     this.creatureName    = creatureName;
     this.moveset         = moveset;
     this.focalPoints     = focalPoints;
     this.creatureAbility = creatureAbility;
     this.baseStats       = baseStats;
     this.availableForms  = availableForms;
     this.baseForm        = baseForm;
     this.currentForm     = baseForm;
 }
Beispiel #5
0
        public void testMoveManagerGetListOfHighestPrio()
        {
            Watchers testWatchers = new Watchers();

            CreatureStats  cs1 = new CreatureStats(1, 1, 1, 10);
            CreatureForm   bf1 = new CreatureForm(new HashSet <CreatureType>(new CreatureType[] { CreatureType.VITAL }), null, null);
            FocusPoint     f1  = new FocusPoint(null, null, null, null);
            FocalPoints    fp1 = new FocalPoints(f1, f1, f1, f1);
            Creature       c1  = new Creature(0, "", null, fp1, null, cs1, bf1, null);
            BattleCreature bc1 = new BattleCreature(c1, Owner.ALLY, testWatchers);

            CreatureStats  cs2 = new CreatureStats(1, 1, 1, 20);
            CreatureForm   bf2 = new CreatureForm(new HashSet <CreatureType>(new CreatureType[] { CreatureType.VITAL }), null, null);
            FocusPoint     f2  = new FocusPoint(null, null, null, null);
            FocalPoints    fp2 = new FocalPoints(f2, f2, f2, f2);
            Creature       c2  = new Creature(0, "", null, fp2, null, cs2, bf2, null);
            BattleCreature bc2 = new BattleCreature(c2, Owner.ALLY, testWatchers);

            Move move1 = new Move(0, "TestMove1", "", Move.MoveClass.ATTACK, TargetClass.ENEMY_SINGLE, null, CreatureType.VITAL, 0, 0, 0);
            Move move2 = new Move(1, "TestMove2", "", Move.MoveClass.ATTACK, TargetClass.ENEMY_SINGLE, null, CreatureType.VITAL, 1, 0, 0);
            Move move3 = new Move(2, "TestMove3", "", Move.MoveClass.ATTACK, TargetClass.ENEMY_SINGLE, null, CreatureType.VITAL, -3, 0, 0);

            MoveContext context1 = new MoveContext(move1, bc1, null, null, null);
            MoveContext context2 = new MoveContext(move2, bc2, null, null, null);
            MoveContext context3 = new MoveContext(move3, bc1, null, null, null);
            MoveContext context4 = new MoveContext(move1, bc2, null, null, null);

            //bc2 moves faster than bc1
            //Order of prio: move3, move1, move2
            //Resulting move order should then be: context3, context4, context1, context2
            HashSet <MoveContext> contexts    = new HashSet <MoveContext>(new MoveContext[] { context1, context2, context3, context4 });
            MoveManager           moveManager = new MoveManager(null, null, contexts);

            MoveContext actual1 = moveManager.getNextMove();
            MoveContext actual2 = moveManager.getNextMove();

            Assert.That(moveManager.getMovesRemaining() == 2);
            Assert.That(moveManager.isTurnOver() == false);

            MoveContext actual3 = moveManager.getNextMove();
            MoveContext actual4 = moveManager.getNextMove();

            Assert.That(moveManager.getMovesRemaining() == 0);
            Assert.That(moveManager.isTurnOver());

            Assert.That(actual1.Equals(context3));
            Assert.That(actual2.Equals(context4));
            Assert.That(actual3.Equals(context1));
            Assert.That(actual4.Equals(context2));
        }
    public override bool Equals(Object obj)
    {
        if (!(obj is FocalPoints))
        {
            return(false);
        }
        FocalPoints other = (FocalPoints)obj;

        bool isEqual = true;

        isEqual &= fp[FocusThreshold.HAZY].Equals(other.fp[FocusThreshold.HAZY]);
        isEqual &= fp[FocusThreshold.ALERT].Equals(other.fp[FocusThreshold.ALERT]);
        isEqual &= fp[FocusThreshold.IN_TUNE].Equals(other.fp[FocusThreshold.IN_TUNE]);
        isEqual &= fp[FocusThreshold.SHARP].Equals(other.fp[FocusThreshold.SHARP]);
        return(isEqual);
    }