Exemplo n.º 1
0
    protected void OnUnitKilled()
    {
        UnitInventory inv = GetComponent <UnitInventory>();

        if (inv.SpaceInInventory())
        {
            Item dropedItem = ItemSpawner.instance.SpawnItem(stats);
            if (dropedItem != null)
            {
                inv.AddItem(dropedItem);
            }
        }
    }
    private void OnEnable()
    {
        itemSlotContainer = transform.Find("ItemSlotContainer");
        //EventHandler.current.HoverOverUIStart();
        //EventHandler.current.onItemDroppedInUnitInventory += () => RefreshInventoryItems();
        EventHandler.current.onItemDroppedInUnitInventory += RefreshInventoryItems;

        switch (unitId)
        {
        case Unit.Id.LumberJack:
            this.inventory = GameObject.Find("Lumber Jack").GetComponent <UnitInventory>();
            break;
        }

        RefreshInventoryItems();
    }
Exemplo n.º 3
0
    public void UnitsGatherFood()
    {
        foreach (GameObject u in unitsInRange)
        {
            UnitInventory unitInventory = u.GetComponent <UnitInventory>();
            if (food > collectSpeed && unitInventory.inventorySize < unitInventory.maxInventorySize)
            {
                unitInventory.CollectFood(collectSpeed);
                food = food - collectSpeed;
                SetFoodFillbar();
            }
            else if (food > 0 && unitInventory.inventorySize < unitInventory.maxInventorySize)
            {
                unitInventory.CollectFood(food);
                food = 0;
                SetFoodFillbar();
            }

            if (wood > collectSpeed && unitInventory.inventorySize < unitInventory.maxInventorySize)
            {
                unitInventory.CollectWood(collectSpeed);
                wood = wood - collectSpeed;
                SetWoodFillbar();
            }
            else if (wood > 0 && unitInventory.inventorySize < unitInventory.maxInventorySize)
            {
                unitInventory.CollectWood(wood);
                wood = 0;
                SetWoodFillbar();
            }

            if (silver > collectSpeed && unitInventory.inventorySize < unitInventory.maxInventorySize)
            {
                unitInventory.CollectSilver(collectSpeed);
                silver = silver - collectSpeed;
                SetSilverFillbar();
            }
            else if (silver > 0 && unitInventory.inventorySize < unitInventory.maxInventorySize)
            {
                unitInventory.CollectSilver(silver);
                silver = 0;
                SetSilverFillbar();
            }
        }
    }
Exemplo n.º 4
0
    //-------------------------------------------------------------------------------------------------
    // unity methods
    //-------------------------------------------------------------------------------------------------
    public override void Awake()
    {
        base.Awake();
        //get the UnitInventory
        List <UnitInventory> uinvl = new List <UnitInventory>(GetComponentsInChildren <UnitInventory>());

        foreach (UnitInventory uinv in uinvl)
        {
            if (uinv.mName == "UnitInventory")
            {
                mUnitInventory = uinv;
            }
        }
        if (uinvl.Count == 0)
        {
            Debug.LogError("UnitInventory is null.");
        }
    }
Exemplo n.º 5
0
    /*public void SetAsTarget()
     * {
     *  GameObject unitToMove = unitManager.selectedUnit;
     *  unitToMove.GetComponent<UnitMovement>().target.position = transform.position;
     * }*/

    public void ReceiveResources()
    {
        foreach (GameObject u in unitsInRange)
        {
            //TODO: Value change notifications
            UnitInventory uInventory = u.GetComponent <UnitInventory>();
            //Food
            if (uInventory.food > foodReceptionSpeed)
            {
                playerResourceManager.AddFood(foodReceptionSpeed);
                uInventory.RemoveFood(foodReceptionSpeed);
            }
            else if (uInventory.food > 0)
            {
                playerResourceManager.AddFood(uInventory.food);
                int foodToRemove = uInventory.food;
                uInventory.RemoveFood(foodToRemove);
            }
            //Wood
            if (uInventory.wood > woodReceptionSpeed)
            {
                playerResourceManager.wood += woodReceptionSpeed;
                uInventory.RemoveWood(woodReceptionSpeed);
            }
            else if (uInventory.wood > 0)
            {
                playerResourceManager.wood += uInventory.wood;
                int woodToRemove = uInventory.wood;
                uInventory.RemoveWood(woodToRemove);
            }
            //Silver
            if (uInventory.silver > silverReceptionSpeed)
            {
                playerResourceManager.silver += silverReceptionSpeed;
                uInventory.RemoveSilver(silverReceptionSpeed);
            }
            else if (uInventory.silver > 0)
            {
                playerResourceManager.silver += uInventory.silver;
                int silverToRemove = uInventory.silver;
                uInventory.RemoveSilver(silverToRemove);
            }
        }
    }
Exemplo n.º 6
0
    void Awake()
    {
        Inventory           = GetComponent <UnitInventory>();
        Stats               = GetComponent <UnitStats>();
        Stats.OnHPDepleted += KillUnit;

        Actions = GetComponent <ActionManager>();
        Actions.SetOwner(this);
        Actions.OnActionSelected   += ActionChanged;
        Actions.OnActionUnselected += ActionChanged;

        AllUnits.Add(this);

        SelectibleObjectBase b = GetComponent <SelectibleObjectBase>();

        if (b == null)
        {
            b = gameObject.AddComponent <SelectibleObjectBase>();
        }

        b.OnSelect   += UnitSelected;
        b.OnHover    += OnHover;
        b.OnHoverEnd += OnHoverEnd;
    }
Exemplo n.º 7
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.º 8
0
        /// <summary>
        /// Adds a new item to units inventory
        /// Unit referece is important so that we can check item level requirement etc.
        /// </summary>
        /// <param name="item">The item to add</param>
        /// <param name="unit">Add unit reference</param>
        /// <param name="quantity">The quantity to add</param>
        public void AddItemToInventory(Item item, Unit unit, int quantity = 1)
        {
            bool breakFlag = false;

            while ((quantity > 0) && (!breakFlag))
            {
                InventoryItem existsAndMoreSpace = UnitInventory.SingleOrDefault(x => (x.Details.ID == item.ID) && (x.Quantity < item.MaxStackableQuantity));
                if (existsAndMoreSpace != null)
                {
                    // Get item from inventory and calculate how many we can add to the already existing stack
                    InventoryItem inInventory         = UnitInventory.First(x => (x.Details.ID == item.ID) && (x.Quantity < item.MaxStackableQuantity));
                    int           maximumToAddInStack = (item.MaxStackableQuantity - inInventory.Quantity);

                    // Add to stack. Either full quantity, or the remaning amount too reach max.
                    int addToQuantity = Math.Min(quantity, maximumToAddInStack);

                    // Add to stack and decrease the quantity added
                    inInventory.AddToQuantity(addToQuantity);
                    quantity -= addToQuantity;
                }
                else
                {
                    if (UnitInventory.Count < MAXIMUM_SPACE_IN_INVENTORY)
                    {
                        // Add new value, but let the While loop add quantity
                        item.ItemUnit = unit;
                        UnitInventory.Add(new InventoryItem(item, 0));
                    }
                    else
                    {
                        _unit.RaiseMessage("There is no space in inventory.");
                        breakFlag = true;
                    }
                }
            }
        }
Exemplo n.º 9
0
	public BaseUnit(BaseUnitData data) {
		_data = data;
		Inventory = new UnitInventory(CreateSlotsData(), _data.BaseEquipment, OnEquipmentUpdate);

		RecalculateParamsInternal();
	}
Exemplo n.º 10
0
 public UnitInfo()
 {
     stats     = new UnitStats();
     inventory = new UnitInventory();
 }
Exemplo n.º 11
0
 public void AddToInventory(UnitInventory inv)
 {
 }
Exemplo n.º 12
0
 public void RemoveFromInventory(UnitInventory inv)
 {
 }
Exemplo n.º 13
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);
    }
Exemplo n.º 14
0
 public void RemoveFromInventory(UnitInventory inv)
 {
     m_item.RemoveFromInventory(inv);
 }
Exemplo n.º 15
0
 public void AddToInventory(UnitInventory inv)
 {
     m_item.AddToInventory(inv);
 }