Exemplo n.º 1
0
    static UnitStats MakeStats(GameObject target, ScriptableUnitConfig conf, Unit_EffectManager effects, M_Math.R_Range range)
    {
        UnitStats stats = target.AddComponent <UnitStats>();

        conf.BaseStats.StartTurnTime = range;

        stats.Init(StatsHelper.GetStatListForInit(conf.BaseStats), effects);

        return(stats);
    }
Exemplo n.º 2
0
    public void Init(List <Stat> stats, Unit_EffectManager effect_manager)
    {
        CurrentStats = stats;

        m_Effects = effect_manager;

        if (effect_manager != null)
        {
            effect_manager.OnEffectAdded   += s => { UpdatedBuffs(); };
            effect_manager.OnEffectRemoved += s => { UpdatedBuffs(); };
        }

        OnStatUpdated += CheckHP;
    }
Exemplo n.º 3
0
    public void SetUnitEfffects(Unit_EffectManager new_effects)
    {
        if (effects != null)
        {
            effects.OnEffectAdded   -= OnEffectUpdated;
            effects.OnEffectRemoved -= OnEffectUpdated;
        }

        effects = new_effects;

        if (effects != null)
        {
            effects.OnEffectAdded   += OnEffectUpdated;
            effects.OnEffectRemoved += OnEffectUpdated;
        }

        base.SetEffects(new_effects.ActiveEffects);
    }
Exemplo n.º 4
0
    public void SetUnit(Unit unit, UI_Unit unitUI)
    {
        m_UnitUI        = unitUI;
        m_Unit          = unit;
        m_EffectManager = m_Unit.GetComponent <Unit_EffectManager>();

        m_EffectManager.OnEffectTick    += SpawnEffectTickNotification;
        m_EffectManager.OnEffectAdded   += SpawnEffectAppliedNotification;
        m_EffectManager.OnEffectRemoved += SpawnEffectExpiredNotification;

        UnitInventory inventory = unit.GetComponent <UnitInventory>();

        inventory.OnInventoryUpdated += SpawnInventoryNotification;

        PlayerInventory.Instance.OnInventoryUpdated += SpawnInventoryNotification;

        Unit.OnTurnStart += ShowActiveEffects;

        Unit.OnUnitKilled += u =>
        {
            if (u == unit)
            {
                RemoveListeners();
            }
            ;
        };

        Unit.OnEvacuated += u =>
        {
            if (u == unit)
            {
                RemoveListeners();
            }
            ;
        };
    }
Exemplo n.º 5
0
    /// <summary>
    /// Returns the instance of a unit
    /// </summary>
    /// <param name="data">Unit Config to determine unit type, stats, actions</param>
    /// <returns></returns>
    public static Unit CreateUnit(ScriptableUnitConfig data, int group, M_Math.R_Range initiative_range, bool hide_player)
    {
        if (data == null)
        {
            Debug.LogWarning("cant create unit, data == null");
            return(null);
        }
        MDebug.Log("^unitCreating Unit " + data.ID);
        GameObject         base_unit      = Instantiate(Resources.Load("base_unit")) as GameObject;
        SpawnLootOnDeath   loot           = base_unit.AddComponent <SpawnLootOnDeath>();
        Unit_EffectManager effect_manager = base_unit.AddComponent <Unit_EffectManager>();
        UnitStats          stats          = MakeStats(base_unit, data, effect_manager, initiative_range);
        UnitInventory      inventory      = MakeInventory(data, base_unit, stats);
        ActionManager      actions        = MakeActions(data, base_unit);


        UnitAdrenalineRushParticleManager adr_particles = base_unit.GetComponent <UnitAdrenalineRushParticleManager>();

        Unit                    m_unit          = base_unit.AddComponent <Unit>();
        GameObject              mesh            = MakeMesh(data, m_unit);
        Unit_UnitDeath          unit_death      = base_unit.AddComponent <Unit_UnitDeath>();
        Unit_UnitEvacuation     unit_evac       = base_unit.AddComponent <Unit_UnitEvacuation>();
        UnitAnimationController animations      = mesh.AddComponent <UnitAnimationController>();
        Unit_SoundController    sound           = base_unit.AddComponent <Unit_SoundController>();
        UnitRotationController  rotator         = base_unit.AddComponent <UnitRotationController>();
        SpeechManager_Unit      speech_mananger = base_unit.AddComponent <SpeechManager_Unit>();

        m_unit.OwnerID = data.Owner;
        m_unit.Config  = data;

        UI_Unit.CreateUnitUI(m_unit);


        sound.Init(m_unit);
        unit_evac.Init(m_unit);
        adr_particles.Init(stats);
        AddActiveTurnIndicator(m_unit, data.Owner == 0);
        GetName(data, base_unit);
        GiveWeapon(data, mesh, inventory);


        loot.Init(m_unit, data.LootCategory);
        effect_manager.SetUnit(m_unit);
        animations.Init(m_unit, mesh);



        speech_mananger.Init(data.SpeechConfig, m_unit);


        if (data.Owner == 1)
        {
            UnitAI ai = MakeAI(data, group, base_unit, m_unit);
            rotator.Init(m_unit.GetComponent <WaypointMover>(), ai.GetLookRotation);

            ai.OnPreferredTargetChange += unit => new TurnEventQueue.AIAggroEvent(ai, unit);
        }
        else
        {
            rotator.Init(m_unit.GetComponent <WaypointMover>(), delegate     { return(m_unit.transform.position + m_unit.transform.forward); });
        }
        //set mesh inactive
        mesh.gameObject.GetComponentsInChildren <Renderer>().ToList().ForEach(rend => rend.enabled = false);
        //and then identify
        InitIdentified(data, m_unit, hide_player);


        return(m_unit);
    }