Exemple #1
0
    void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
        }

        DontDestroyOnLoad(gameObject);

        board.Initialize(boardSize);
        board.ShowGrid = true;

        Resources.LoadAll <TileUnitData>("ScriptableObjects");
        Resources.LoadAll <Formation>("Formation");
        TileUnitDatas = Resources.FindObjectsOfTypeAll <ActionUnitData>().Where(x => x.Level == 1).Cast <TileUnitData>().ToList();
        if (TileUnitDatas.Count == 0)
        {
            Debug.Log("Could not find any tile unit data scriptable objects");
        }
        List <Formation> lst = Resources.FindObjectsOfTypeAll <Formation>().Where(x => x.PrevLevel == null).ToList();

        foreach (Formation f in lst)
        {
            FormationManager.Instance.Formations.Add(FormationFacade.CreateFromFormation(f));
        }
        // FormationManager.Instance.Formations = Resources.FindObjectsOfTypeAll<Formation>().Where(x => x.PrevLevel == null).Select(x => FormationFacade.CreateFromFormation(x)).ToList();

        RegisterEvent();
        Profile = new PlayerProfile();
    }
Exemple #2
0
    public FormationFacade Check(int group, FormationCheckType checkType = FormationCheckType.All)
    {
        this.GroupOwner = group;
        foreach (FormationConditionFacade c in Conditions)
        {
            if (!c.ValidCondition(group))
            {
                if ((checkType == FormationCheckType.All || checkType == FormationCheckType.Prev) && PrevLevel != null)
                {
                    FormationFacade result = PrevLevel.Check(group, FormationCheckType.Prev);
                    if (result != null)
                    {
                        return(result);
                    }
                }
                return(null);
            }
        }
        if ((checkType == FormationCheckType.All || checkType == FormationCheckType.Next) && NextLevel != null)
        {
            FormationFacade result = NextLevel.Check(group, FormationCheckType.Next);
            if (result != null)
            {
                return(result);
            }
        }

        return(this);
    }
Exemple #3
0
    internal void ApplyFormation()
    {
        Debug.Log("Formation Check Apply");
        ActiveFormations.ForEach(x =>
        {
            x.RemoveBuff();
        });
        List <FormationFacade> validFormations = new List <FormationFacade>();

        GroupChecks = ActionUnitManger.Instance.Groups;
        Events.InvokeOnAction(EVENT_CHECK_BEFORE);
        foreach (int group in GroupChecks)
        {
            foreach (FormationFacade f in Formations)
            {
                FormationFacade valid = FormationFacade.CreateFromFormation(f.Formation);
                valid = valid.Check(group);
                if (valid != null)
                {
                    valid.GroupOwner = group;
                    Debug.Log("Formation Found match formation " + group);
                    validFormations.Add(valid);
                }
            }
        }

        ActiveFormations = validFormations;
        Events.InvokeOnAction(EVENT_FORMATION_APPLY);
        ActiveFormations.ForEach(x =>
        {
            x.ApplyBuff();
        });

        // bool existsRemove = false;
        // bool existsNew = false;
        // ActiveFormations.Where(x => !validFormations.Contains(x)).ToList().ForEach(x =>
        // {
        //     existsRemove = true;
        //     x.RemoveBuff();
        // });
        // if (existsRemove) ActiveFormations.RemoveAll(x => !validFormations.Contains(x));
        // validFormations.Where(x => !ActiveFormations.Contains(x)).ToList().ForEach(x =>
        // {
        //     existsNew = true;
        //     x.ApplyBuff(0);
        // });
        // if (existsNew) ActiveFormations.AddRange(validFormations.Where(x => !ActiveFormations.Contains(x)));
    }
Exemple #4
0
    public static FormationFacade CreateFromFormation(Formation f)
    {
        if (f == null)
        {
            return(null);
        }
        FormationFacade facade = new FormationFacade();

        facade.Formation  = f.Clone <Formation>();
        facade.Conditions = new FormationConditionFacade[facade.Formation.Conditions.Length];
        for (int i = 0; i < facade.Conditions.Length; i++)
        {
            facade.Conditions[i] = FormationConditionFacade.CreateFromFormation(facade.Formation.Conditions[i]);
        }
        facade.NextLevel = FormationFacade.CreateFromFormation(facade.Formation.NextLevel);
        if (facade.NextLevel != null)
        {
            facade.NextLevel.PrevLevel = facade;
        }
        // facade.PrevLevel = FormationFacade.CreateFromFormation(facade.Formation.PrevLevel);
        return(facade);
    }