Exemple #1
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
     _baseItemTemplateTypes = ItemTemplateLoader.GetItemTemplateTypes();
     PopulatePrefabDictionaries();
 }
Exemple #2
0
    private List <ItemTemplate> GetWeaponTemplateByProperty(string property)
    {
        var templatesForProperty = new List <ItemTemplate>();

        foreach (var templateType in _baseItemTemplateTypes)
        {
            var template = ItemTemplateLoader.GetItemTemplate(templateType);

            if (template.Category == "weapon" &&
                template.Properties.Contains(property))
            {
                templatesForProperty.Add(template);
            }
        }

        return(templatesForProperty);
    }
Exemple #3
0
    public Item GetRandomItemByEquipmentSlot(Entity.EquipmentSlot slot, ItemRarity rarityCap = ItemRarity.Common)
    {
        var templatesForSlot = new List <ItemTemplate>();

        foreach (var templateType in _baseItemTemplateTypes)
        {
            var currentTemplate = ItemTemplateLoader.GetItemTemplate(templateType);

            var validSlots = GetEquipmentSlotsForSlotType(currentTemplate.EquipmentSlotType);

            if (validSlots.Contains(slot))
            {
                templatesForSlot.Add(currentTemplate);
            }
        }

        if (templatesForSlot.Count < 1)
        {
            return(null);
        }

        var itemTemplate = templatesForSlot[Random.Range(0, templatesForSlot.Count)];

        if (rarityCap == ItemRarity.Common)
        {
            return(GetItemFromTemplate(itemTemplate, rarityCap));
        }

        const int maxTries = 2;

        var rarity = GlobalHelper.GetRandomEnumValue <ItemRarity>();

        var currentTry = 1;

        while (currentTry <= maxTries && rarity > rarityCap)
        {
            rarity = GlobalHelper.GetRandomEnumValue <ItemRarity>();
            currentTry++;
        }

        return(GetItemFromTemplate(itemTemplate, rarity));
    }
Exemple #4
0
    public Weapon GetRandomRangedWeapon(ItemRarity rarityCap = ItemRarity.Common)
    {
        var rangedTemplates = new List <ItemTemplate>();

        foreach (var templateType in _baseItemTemplateTypes)
        {
            var currentTemplate = ItemTemplateLoader.GetItemTemplate(templateType);

            if (currentTemplate.Category == "weapon" &&
                currentTemplate.EquipmentSlotType == EquipmentSlotType.Missile ||
                currentTemplate.EquipmentSlotType == EquipmentSlotType.Thrown)
            {
                rangedTemplates.Add(currentTemplate);
            }
        }

        var weaponTemplate = rangedTemplates[Random.Range(0, rangedTemplates.Count)];

        if (rarityCap == ItemRarity.Common)
        {
            return(new Weapon(weaponTemplate, rarityCap));
        }

        const int maxTries = 3;

        var rarity = GlobalHelper.GetRandomEnumValue <ItemRarity>();

        var currentTry = 1;

        while (currentTry <= maxTries && rarity > rarityCap)
        {
            rarity = GlobalHelper.GetRandomEnumValue <ItemRarity>();
            currentTry++;
        }

        return(new Weapon(weaponTemplate, rarity));
    }
Exemple #5
0
    private void PlaceSettlementProps()
    {
        var propChance = 99;

        var roll = Random.Range(1, 101);

        while (roll <= propChance)
        {
            var propType = SettlementPrefabStore.GetRandomPropType();

            var blueprintChance = 17;

            roll = Random.Range(1, 101);

            if (roll <= blueprintChance)
            {
                // todo not implemented
                while (propType == SettlementPrefabStore.SettlementPropType.Fence)
                {
                    propType = SettlementPrefabStore.GetRandomPropType();
                }

                var propBlueprint = SettlementPrefabStore.GetPropBlueprintByType(propType);

                var areaRow            = Random.Range(0, Height);
                var startingAreaColumn = Random.Range(0, Width);
                var currentAreaColumn  = startingAreaColumn;

                var blueprintHeight = propBlueprint.GetLength(0);
                var blueprintWidth  = propBlueprint.GetLength(1);

                var propPrefabs = new Dictionary <char, List <GameObject> >();

                for (var currentRow = 0; currentRow < blueprintHeight; currentRow++)
                {
                    for (var currentColumn = 0; currentColumn < blueprintWidth; currentColumn++)
                    {
                        if (areaRow < 0 || areaRow >= Height || currentAreaColumn < 0 || currentAreaColumn >= Width)
                        {
                            continue;
                        }

                        var currentTile = AreaTiles[areaRow, currentAreaColumn];

                        //todo should probably make a tile type enum because this is trash
                        if (currentTile.PresentWallTile != null ||
                            currentTile.GetPrefabTileTexture().name.Contains("floor") ||
                            currentTile.GetPrefabTileTexture().name.Contains("road") ||
                            currentTile.GetPrefabTileTexture().name.Contains("path") ||
                            currentTile.GetBlocksMovement())
                        {
                            continue;
                        }

                        var currentKey = propBlueprint[currentRow, currentColumn];

                        if (!propPrefabs.ContainsKey(currentKey))
                        {
                            var prefabsForCurrentKey = SettlementPrefabStore.GetPropPrefabsByKey(currentKey);

                            propPrefabs.Add(currentKey, prefabsForCurrentKey);
                        }

                        if (propPrefabs[currentKey] == null || propPrefabs[currentKey].Count < 1)
                        {
                            continue;
                        }

                        GameObject prefab = null;
                        if (currentKey != SettlementPrefabStore.TurretKey)
                        {
                            prefab = propPrefabs[currentKey][Random.Range(0, propPrefabs[currentKey].Count)];
                        }

                        if (currentKey == SettlementPrefabStore.FieldKey)
                        {
                            //todo pick field type
                            currentTile.PresentProp = new Field(FieldType.Wheat, currentKey.ToString(), prefab);
                        }
                        else if (currentKey == SettlementPrefabStore.GraveyardKey)
                        {
                            currentTile.PresentProp = new Grave(currentKey.ToString(), prefab);
                        }
                        else if (currentKey == SettlementPrefabStore.TurretKey)
                        {
                            continue;

                            var template = EntityTemplateLoader.GetEntityTemplate("turret");

                            var turret = new Entity(template, Settlement.Faction);

                            //todo need to implement
                            var turretBarrel = new Weapon(ItemTemplateLoader.GetItemTemplate("TurretBarrel"),
                                                          GlobalHelper.GetRandomEnumValue <ItemRarity>());

                            turret.EquipItem(turretBarrel, Entity.EquipmentSlot.Special);

                            currentTile.SetPresentEntity(turret);
                        }
                        else
                        {
                            currentTile.PresentProp = new Prop(currentKey.ToString(), prefab);
                        }

                        currentAreaColumn++;
                    }

                    areaRow++;
                    currentAreaColumn = startingAreaColumn;
                }
            }
            else
            {
                var prefabs = SettlementPrefabStore.GetPropPrefabByType(propType);

                if (prefabs == null)
                {
                    continue;
                }

                var areaRow    = Random.Range(0, Height);
                var areaColumn = Random.Range(0, Width);

                var currentTile = AreaTiles[areaRow, areaColumn];

                //todo should probably make a tile type enum because this is trash
                if (currentTile.PresentWallTile != null ||
                    currentTile.GetPrefabTileTexture().name.Contains("floor") ||
                    currentTile.GetPrefabTileTexture().name.Contains("road") ||
                    currentTile.GetPrefabTileTexture().name.Contains("path") ||
                    currentTile.GetBlocksMovement())
                {
                    continue;
                }

                if (propType == SettlementPrefabStore.SettlementPropType.Field)
                {
                    var index = Random.Range(0, prefabs.Count);

                    currentTile.PresentProp = new Field(FieldType.Wheat, index.ToString(), prefabs[index]);
                }
                else if (propType == SettlementPrefabStore.SettlementPropType.Security)
                {
                    continue;

                    var template = EntityTemplateLoader.GetEntityTemplate("turret");

                    var turret = new Entity(template, Settlement.Faction);

                    //todo need to implement
                    var turretBarrel = new Weapon(ItemTemplateLoader.GetItemTemplate("TurretBarrel"),
                                                  GlobalHelper.GetRandomEnumValue <ItemRarity>());

                    turret.EquipItem(turretBarrel, Entity.EquipmentSlot.Special);

                    currentTile.SetPresentEntity(turret);

                    //todo raise new entity event
                }
                else
                {
                    var index = Random.Range(0, prefabs.Count);

                    currentTile.PresentProp = new Prop(index.ToString(), prefabs[index]);
                }
            }

            propChance -= 23;

            if (propChance < 1)
            {
                propChance = 1;
            }

            roll = Random.Range(1, 101);
        }
    }
Exemple #6
0
    //<Summary>
    //    Returns a random base item template
    //</Summary>
    private ItemTemplate GetRandomBaseItemTemplate()
    {
        var itemType = _baseItemTemplateTypes[Random.Range(0, _baseItemTemplateTypes.Count)];

        return(ItemTemplateLoader.GetItemTemplate(itemType));
    }
Exemple #7
0
    private Item CreateItemOfType(string itemType, ItemRarity rarity = ItemRarity.Common)
    {
        var itemTemplate = ItemTemplateLoader.GetItemTemplate(itemType);

        return(GetItemFromTemplate(itemTemplate, rarity));
    }