Exemplo n.º 1
0
    private void EquipAppearanceItem(RavenNest.Models.Item item)
    {
        int.TryParse(
            this.appearance.Gender == Gender.Male
            ? item.MaleModelId
            : item.FemaleModelId, out var modelId);

        switch (item.Type)
        {
        case ItemType.Gloves:
            appearance.HandModelNumber = modelId;
            appearance.HandMaterial    = item.Material;
            break;

        case ItemType.Chest:
            appearance.TorsoModelNumber = modelId;
            appearance.TorsoMaterial    = item.Material;
            break;

        case ItemType.Leggings:
            appearance.BottomModelNumber = modelId;
            appearance.BottomMaterial    = item.Material;
            break;

        case ItemType.Boots:
            appearance.FeetModelNumber = modelId;
            appearance.FeetMaterial    = item.Material;
            break;
        }
    }
Exemplo n.º 2
0
    public void Equip(RavenNest.Models.Item item, bool updateAppearance = true)
    {
        var equip = GetEquipmentOfType(item.Category, item.Type);

        if (equip != null)
        {
            this.Add(equip);
            equipped.Remove(equip);
            equipment.Unequip(equip.Id);
        }

        equipped.Add(item);
        this.Remove(item, 1);

        if (updateAppearance)
        {
            equipment.EquipAll(this.equipped);
        }
        else
        {
            equipment.Equip(item);
        }

        player.UpdateCombatStats(this.equipped);
    }
Exemplo n.º 3
0
    public void Equip(RavenNest.Models.Item item)
    {
        if (!baseItemPrefab)
        {
            Debug.LogError("BaseItemPrefab not set on player!! Unable to create item");
            return;
        }

        var existingItemController = equippedObjects.FirstOrDefault(x => x.Id == item.Id);

        if (existingItemController != null && existingItemController)
        {
            Destroy(existingItemController.gameObject);
            equippedObjects.Remove(existingItemController);
        }

        var itemController = gameManager.Items.Create(item, player.Appearance.Gender == Gender.Male);

        itemController.transform.SetParent(transform);
        itemController.gameObject.layer = player.gameObject.layer;

        equippedObjects.Add(itemController);
        appearance.Equip(itemController);

        if (itemController.Type == ItemType.Shield)
        {
            SetShield(itemController);
        }

        if (itemController.Category == ItemCategory.Weapon)
        {
            SetWeapon(itemController);
        }
    }
Exemplo n.º 4
0
    public bool EquipIfBetter(RavenNest.Models.Item item)
    {
        if (item.RequiredDefenseLevel > Stats.Defense.Level)
        {
            return(false);
        }

        if (item.RequiredAttackLevel > Stats.Attack.Level)
        {
            return(false);
        }

        var currentEquipment = Inventory.GetEquipmentOfType(item.Category, item.Type);

        if (currentEquipment == null)
        {
            Equip(item);
            return(true);
        }

        if (currentEquipment.GetTotalStats() < item.GetTotalStats())
        {
            Equip(item);
            return(true);
        }

        return(false);
    }
Exemplo n.º 5
0
    public int Compare(RavenNest.Models.Item item)
    {
        var stats1 = WeaponAim + WeaponPower + ArmorPower;
        var stats2 = item.WeaponAim + item.WeaponPower + item.ArmorPower;

        return(stats1 - stats2);
    }
Exemplo n.º 6
0
    public ItemController Create(RavenNest.Models.Item item, bool useMalePrefab)
    {
        definition = item;

        gameObject.name = item.Name;

        transform.localPosition = Vector3.zero;
        transform.localRotation = Quaternion.identity;

        Id    = item.Id;
        Name  = item.Name;
        Level = item.Level;

        WeaponAim   = item.WeaponAim;
        WeaponPower = item.WeaponPower;
        ArmorPower  = item.ArmorPower;

        RequiredAttackLevel  = item.RequiredAttackLevel;
        RequiredDefenseLevel = item.RequiredDefenseLevel;

        Category          = item.Category;
        Type              = item.Type;
        Material          = item.Material;
        FemaleModelID     = item.FemaleModelId;
        MaleModelID       = item.MaleModelId;
        GenericPrefabPath = item.GenericPrefab;
        MalePrefabPath    = item.MalePrefab;
        FemalePrefabPath  = item.FemalePrefab;
        IsGenericModel    = item.IsGenericModel.GetValueOrDefault();

        if (!prefab)
        {
            var path = IsGenericModel
                ? GenericPrefabPath
                : useMalePrefab
                    ? MalePrefabPath
                    : FemalePrefabPath;

            if (string.IsNullOrEmpty(path))
            {
                return(this);
            }

            prefab = Resources.Load <GameObject>(path);
            if (!prefab)
            {
                //Debug.LogError(this.name + " failed to load prefab: " + path);
                return(this);
            }

            model = Instantiate(prefab, transform) as GameObject;
        }

        return(this);
    }
Exemplo n.º 7
0
    public void RemoveResources(RavenNest.Models.Item item)
    {
        if (item.WoodCost > 0)
        {
            RemoveResource(Resource.Woodcutting, item.WoodCost);
        }

        if (item.OreCost > 0)
        {
            RemoveResource(Resource.Mining, item.OreCost);
        }
    }
Exemplo n.º 8
0
    public void Create(RavenNest.Models.Item item, bool useMalePrefab)
    {
        this.definition = item;

        this.gameObject.name = item.Name;

        this.transform.localPosition = Vector3.zero;
        this.transform.localRotation = Quaternion.identity;

        this.Id    = item.Id;
        this.Name  = item.Name;
        this.Level = item.Level;

        this.WeaponAim   = item.WeaponAim;
        this.WeaponPower = item.WeaponPower;
        this.ArmorPower  = item.ArmorPower;

        this.RequiredAttackLevel  = item.RequiredAttackLevel;
        this.RequiredDefenseLevel = item.RequiredDefenseLevel;

        this.Category          = item.Category;
        this.Type              = item.Type;
        this.Material          = item.Material;
        this.FemaleModelID     = item.FemaleModelId;
        this.MaleModelID       = item.MaleModelId;
        this.GenericPrefabPath = item.GenericPrefab;
        this.MalePrefabPath    = item.MalePrefab;
        this.FemalePrefabPath  = item.FemalePrefab;
        this.IsGenericModel    = item.IsGenericModel.GetValueOrDefault();

        if (!prefab)
        {
            var path = IsGenericModel
                ? this.GenericPrefabPath
                : useMalePrefab
                    ? this.MalePrefabPath
                    : this.FemalePrefabPath;

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            this.prefab = Resources.Load <GameObject>(path);
            if (!prefab)
            {
                //Debug.LogError(this.name + " failed to load prefab: " + path);
                return;
            }

            this.model = Instantiate(prefab, this.transform) as GameObject;
        }
    }
Exemplo n.º 9
0
    private bool CanCraftItem(PlayerController player, RavenNest.Models.Item item)
    {
        var requirements = item;

        if (requirements.RequiredCraftingLevel > player.Stats.Crafting.CurrentValue)
        {
            return(false);
        }

        //if (requirements.MinCookingLevel > player.Stats.Cooking.CurrentValue)
        //    return false;

        return(true);
    }
Exemplo n.º 10
0
    public async void AddItem(RavenNest.Models.Item item)
    {
        Inventory.Add(item);
        var result = await gameManager.RavenNest.Players.AddItemAsync(this.UserId, item.Id);

        if (result == AddItemResult.Failed)
        {
            Debug.LogError("Item add for user: "******", item: " + item.Id + ", result: " + result);
        }
        else
        {
            Debug.Log("Item add for user: "******", item: " + item.Id + ", result: " + result);
        }
    }
Exemplo n.º 11
0
    public void DropItem(PlayerController player,
                         DropType dropType   = DropType.Standard,
                         string messageStart = "You found")
    {
        if (items == null || items.Length == 0)
        {
            return;
        }
        var guaranteedDrop = dropType == DropType.MagicRewardGuaranteed || dropType == DropType.StandardGuaranteed;

        do
        {
            var allItems = gameManager.Items.GetItems();

            var droppableItems = items.Select(x =>
            {
                RavenNest.Models.Item item = null;
                if (Guid.TryParse(x.ItemID, out var itemId))
                {
                    item = allItems.FirstOrDefault(y => y.Id == itemId);
                }
                else
                {
                    item = allItems.FirstOrDefault(y => y.Name.IndexOf(x.ItemID, StringComparison.OrdinalIgnoreCase) >= 0);
                }
                return(new
                {
                    Item = item,
                    x.DropChance
                });
            })
                                 .Where(x => x.Item != null)
                                 .OrderByDescending(x => x.DropChance).ToList();

            foreach (var item in droppableItems)
            {
                //if (player.Stats.Attack.Level < item.Item.RequiredAttackLevel ||
                //    player.Stats.Defense.Level < item.Item.RequiredDefenseLevel)
                //    continue;

                if (UnityEngine.Random.value <= item.DropChance)
                {
                    player.PickupItem(item.Item, messageStart);
                    return;
                }
            }
        } while (guaranteedDrop);
    }
Exemplo n.º 12
0
    public void Add(RavenNest.Models.Item item, decimal amount = 1)
    {
        var existing = backpack.FirstOrDefault(x => x.Item.Id == item.Id);

        if (existing != null)
        {
            existing.Amount += amount;
        }
        else
        {
            backpack.Add(new GameInventoryItem
            {
                Item   = item,
                Amount = amount
            });
        }
    }
Exemplo n.º 13
0
    private void EquipBestItem(ItemCategory category, ItemType?type = null)
    {
        var equippedItem = type != null
            ? GetEquipmentOfType(category, type.Value)
            : GetEquipmentOfCategory(category);

        var bestValue = equippedItem != null
            ? equippedItem.WeaponPower + equippedItem.WeaponAim + equippedItem.ArmorPower
            : 0;

        if (player.IsDiaperModeEnabled &&
            category != ItemCategory.Weapon &&
            category != ItemCategory.Pet &&
            category != ItemCategory.Ring)
        {
            return;
        }

        RavenNest.Models.Item bestItem = null;
        foreach (var item in type != null
            ? backpack.Where(x => x.Item.Category == category && x.Item.Type == type)
            : backpack.Where(x => x.Item.Category == category))
        {
            var itemValue = GetItemValue(item);
            var canEquip  = CanEquipItem(item);

            if (equippedItem != null && equippedItem.Name == item.Item.Name)
            {
                continue;
            }

            if (bestValue < itemValue && canEquip)
            {
                bestValue = itemValue;
                bestItem  = item.Item;
            }
        }

        if (bestItem != null)
        {
            Equip(bestItem, false);
        }
    }
Exemplo n.º 14
0
    private bool GotEnoughResources(PlayerController player, RavenNest.Models.Item item)
    {
        if (item.OreCost > player.Resources.Ore)
        {
            return(false);
        }

        if (item.WoodCost > player.Resources.Wood)
        {
            return(false);
        }

        //if (item.FishCost > player.Resources.Fish)
        //    return false;

        //if (item.WheatCost > player.Resources.Wheat)
        //    return false;

        return(true);
    }
Exemplo n.º 15
0
    private void EquipBestItem(ItemCategory category, ItemType?type = null)
    {
        var equippedItem = type != null
            ? GetEquipmentOfType(category, type.Value)
            : GetEquipmentOfCategory(category);

        var bestValue = equippedItem != null
            ? equippedItem.WeaponPower + equippedItem.WeaponAim + equippedItem.ArmorPower
            : 0;

        RavenNest.Models.Item bestItem = null;
        foreach (var item in type != null
            ? backpack.Where(x => x.Item.Category == category && x.Item.Type == type)
            : backpack.Where(x => x.Item.Category == category))
        {
            var itemValue = item.Item.WeaponPower + item.Item.WeaponAim + item.Item.ArmorPower;
            var canEquip  = player.Stats.Defense.CurrentValue >= item.Item.RequiredDefenseLevel &&
                            player.Stats.Attack.CurrentValue >= item.Item.RequiredAttackLevel;

            if (equippedItem != null && equippedItem.Name == item.Item.Name)
            {
                continue;
            }

            if (bestValue < itemValue && canEquip)
            {
                bestValue = itemValue;
                bestItem  = item.Item;
            }
        }

        if (bestItem != null)
        {
            Equip(bestItem, false);
        }
    }
Exemplo n.º 16
0
 private void Equip(RavenNest.Models.Item item)
 {
     Inventory.Equip(item);
 }
Exemplo n.º 17
0
    public void Equip(RavenNest.Models.Item item)
    {
        if (!baseItemPrefab)
        {
            Debug.LogError("BaseItemPrefab not set on player!! Unable to create item");
            return;
        }

        var existingItemController = equippedObjects.FirstOrDefault(x => x.Id == item.Id);

        if (existingItemController != null && existingItemController)
        {
            Destroy(existingItemController.gameObject);
            equippedObjects.Remove(existingItemController);
        }

        var itemController = Instantiate(baseItemPrefab, this.transform).GetComponent <ItemController>();

        itemController.Create(item, player.Appearance.Gender == Gender.Male);
        equippedObjects.Add(itemController);

        itemController.gameObject.layer = player.gameObject.layer;

        if (item.Category == ItemCategory.Weapon)
        {
            SetWeapon(itemController);
        }
        else
        {
            if (IsAppearanceItem(item.Type))
            {
                EquipAppearanceItem(item);
                return;
            }

            switch (item.Type)
            {
            case ItemType.Helm:
            {
                appearance.HideHair();
                appearance.SetItem(itemController, appearance.EquipHead);
            }
            break;

            case ItemType.Amulet:
                appearance.SetItem(itemController, appearance.EquipNeck);
                break;

            case ItemType.Shield:
                appearance.SetItem(itemController, appearance.EquipLHand);
                break;

            case ItemType.LeftShoulder:
                appearance.SetItem(itemController, appearance.EquipLShoulder);
                break;

            case ItemType.RightShoulder:
                appearance.SetItem(itemController, appearance.EquipRShoulder);
                break;
            }
        }
    }