Exemplo n.º 1
0
    // Async method for skills
    private IEnumerator SkillsAsync(CharacterScript character, EventTypes eventType, Skills skill, SkillsCallBack callback)
    {
        Entity entity = character.transform.GetComponent(typeof(Entity)) as Entity;

        IsoUnity.Cell characterCurrentCell = character.transform.parent.transform.GetComponent(typeof(IsoUnity.Cell)) as IsoUnity.Cell;
        try
        {
            entity.mover.maxJumpSize = character.character.attributesWithFormulas.Find(x => x.attribute.id == moveHeight.id).value;
        }
        catch (NullReferenceException e)
        {
            Debug.Log("Character '" + character.character.name + "' doesn't have attribute '" + moveHeight.name + "'");
        }

        selectedCellEvent = new GameEvent("selected cell", new Dictionary <string, object>()
        {
            { "synchronous", true }
        });

        Game.main.enqueueEvent(selectedCellEvent);
        // Get all characters
        List <CharacterScript> characters = FindObjectsOfType <CharacterScript>().ToList();
        List <CharacterScript> targets    = null;

        // Switch
        if (skill.skillType == SkillTypes.SINGLE_TARGET)
        {
            foreach (CharacterScript target in characters)
            {
                IsoUnity.Cell targetCell = target.transform.parent.transform.GetComponent(typeof(IsoUnity.Cell)) as IsoUnity.Cell;
                PaintCell(targetCell, eventType);
            }
        }
        else if (skill.skillType == SkillTypes.AREA)
        {
            targets = CalculateDistanceArea(entity, characterCurrentCell, eventType, skill.areaRange, int.MaxValue);
            PaintCell(characterCurrentCell, eventType);
        }
        else if (skill.skillType == SkillTypes.AREA_IN_OBJETIVE)
        {
            foreach (IsoUnity.Cell cell in characterCurrentCell.Map.Cells)
            {
                showSelector(cell, eventType, ((result) => {
                    cleanSkillCells();
                    targets = CalculateDistanceArea(null, result, eventType, skill.areaRange, int.MaxValue);
                    PaintCell(cell, eventType);
                }));
            }
        }

        Dictionary <string, object> outParams;

        yield return(new WaitForEventFinished(selectedCellEvent, out outParams));

        cleanCells();
        IsoUnity.Cell selectedCell = outParams["cell"] as IsoUnity.Cell;
        Cell          returnCell   = new Cell((int)selectedCell.Map.getCoords(selectedCell.gameObject).x, (int)selectedCell.Map.getCoords(selectedCell.gameObject).y);

        if (skill.skillType == SkillTypes.SINGLE_TARGET)
        {
            targets = new List <CharacterScript>();
            targets.Add(selectedCell.transform.GetComponentInChildren <CharacterScript>());
        }

        var showDecoration = new GameEvent("show decoration animation", new Dictionary <string, object>()
        {
            { "objective", targets[0].gameObject },
            { "animation", skill.animationName },
            { "synchronous", true }
        });

        Game.main.enqueueEvent(showDecoration);

        yield return(new WaitForEventFinished(showDecoration));

        callback(returnCell, true, targets);
    }
Exemplo n.º 2
0
 // Skills
 public void Skills(CharacterScript character, EventTypes eventType, SkillsCallBack callback, Skills skill = null)
 {
     StartCoroutine(SkillsAsync(character, eventType, skill, callback));
 }