refactored items
This commit is contained in:
parent
2528c3e4dd
commit
d7424ed972
@ -12,31 +12,21 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: effbc11b6ae8444c8d20e929ce28183e, type: 3}
|
m_Script: {fileID: 11500000, guid: effbc11b6ae8444c8d20e929ce28183e, type: 3}
|
||||||
m_Name: ItemData
|
m_Name: ItemData
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
itemInfos:
|
items:
|
||||||
- prefab: {fileID: 3197816592181874056, guid: f0b68f1afd77d7741a0fe8ff5ba25a77,
|
- item: {fileID: 11400000, guid: e7adbedb55c5db341a823370b696f709, type: 2}
|
||||||
|
iconPrefab: {fileID: 3197816592181874056, guid: 2704c4f795b0d7748a3e3fa53be4d893,
|
||||||
type: 3}
|
type: 3}
|
||||||
isInstantUse: 0
|
|
||||||
type: Tower
|
|
||||||
icon: {fileID: 21300000, guid: 543c4732bd2d47a41bdbbf2156eb358c, type: 3}
|
|
||||||
spawnablePrefab: {fileID: 3496656575117217171, guid: 38edd53c7f09f41409153241c78268f9,
|
|
||||||
type: 3}
|
|
||||||
values:
|
|
||||||
spawnChance: 1
|
|
||||||
- prefab: {fileID: 3197816592181874056, guid: 2704c4f795b0d7748a3e3fa53be4d893,
|
|
||||||
type: 3}
|
|
||||||
isInstantUse: 1
|
|
||||||
type: AttackBonus
|
|
||||||
icon: {fileID: 21300000, guid: caf8bc0311dd2fc4ca1528a82a063754, type: 3}
|
icon: {fileID: 21300000, guid: caf8bc0311dd2fc4ca1528a82a063754, type: 3}
|
||||||
spawnablePrefab: {fileID: 0}
|
_spawnChance: 0.581
|
||||||
values: 0300000064000000
|
- item: {fileID: 11400000, guid: 62849ddbcd32e834887aac5eb3d98db0, type: 2}
|
||||||
spawnChance: 0
|
iconPrefab: {fileID: 8639522512577941448, guid: 7b6a7f64e52da514d88aa97ad8f863df,
|
||||||
- prefab: {fileID: 8639522512577941448, guid: 7b6a7f64e52da514d88aa97ad8f863df,
|
|
||||||
type: 3}
|
type: 3}
|
||||||
isInstantUse: 1
|
|
||||||
type: DefenceBonus
|
|
||||||
icon: {fileID: 21300000, guid: 35be128594dcdce48b5d8e5317b38ed9, type: 3}
|
icon: {fileID: 21300000, guid: 35be128594dcdce48b5d8e5317b38ed9, type: 3}
|
||||||
spawnablePrefab: {fileID: 0}
|
_spawnChance: 0.67
|
||||||
values: 0a0000001e000000
|
- item: {fileID: 11400000, guid: ef628c3158b0ea34bb919ca105507009, type: 2}
|
||||||
spawnChance: 0
|
iconPrefab: {fileID: 3197816592181874056, guid: f0b68f1afd77d7741a0fe8ff5ba25a77,
|
||||||
fromTimeSpawn: 3
|
type: 3}
|
||||||
|
icon: {fileID: 21300000, guid: b7771b47a72ca7947bf18f664e53a983, type: 3}
|
||||||
|
_spawnChance: 0.921
|
||||||
|
fromTimeSpawn: 2.93
|
||||||
toTimeSpawn: 10
|
toTimeSpawn: 10
|
||||||
|
8
Assets/Resources/Data/Items.meta
Normal file
8
Assets/Resources/Data/Items.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c6b240b41035a1a49a6eb7919af5882e
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
20
Assets/Resources/Data/Items/AttackBonus.asset
Normal file
20
Assets/Resources/Data/Items/AttackBonus.asset
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 2b016eba27de41629261b965b3e2be0c, type: 3}
|
||||||
|
m_Name: AttackBonus
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
iconPrefab: {fileID: 3197816592181874056, guid: 2704c4f795b0d7748a3e3fa53be4d893,
|
||||||
|
type: 3}
|
||||||
|
icon: {fileID: 21300000, guid: caf8bc0311dd2fc4ca1528a82a063754, type: 3}
|
||||||
|
duration: 3
|
||||||
|
value: 100
|
||||||
|
type: 0
|
8
Assets/Resources/Data/Items/AttackBonus.asset.meta
Normal file
8
Assets/Resources/Data/Items/AttackBonus.asset.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e7adbedb55c5db341a823370b696f709
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
20
Assets/Resources/Data/Items/DefenceBonus.asset
Normal file
20
Assets/Resources/Data/Items/DefenceBonus.asset
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 2b016eba27de41629261b965b3e2be0c, type: 3}
|
||||||
|
m_Name: DefenceBonus
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
iconPrefab: {fileID: 8639522512577941448, guid: 7b6a7f64e52da514d88aa97ad8f863df,
|
||||||
|
type: 3}
|
||||||
|
icon: {fileID: 21300000, guid: 35be128594dcdce48b5d8e5317b38ed9, type: 3}
|
||||||
|
duration: 15
|
||||||
|
value: 50
|
||||||
|
type: 1
|
8
Assets/Resources/Data/Items/DefenceBonus.asset.meta
Normal file
8
Assets/Resources/Data/Items/DefenceBonus.asset.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 62849ddbcd32e834887aac5eb3d98db0
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
19
Assets/Resources/Data/Items/Tower.asset
Normal file
19
Assets/Resources/Data/Items/Tower.asset
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: f23a091c5733400f8f0092a4c0f33c6e, type: 3}
|
||||||
|
m_Name: Tower
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
iconPrefab: {fileID: 3197816592181874056, guid: f0b68f1afd77d7741a0fe8ff5ba25a77,
|
||||||
|
type: 3}
|
||||||
|
icon: {fileID: 21300000, guid: b7771b47a72ca7947bf18f664e53a983, type: 3}
|
||||||
|
buildingPrefab: {fileID: 3496656575117217171, guid: 38edd53c7f09f41409153241c78268f9,
|
||||||
|
type: 3}
|
8
Assets/Resources/Data/Items/Tower.asset.meta
Normal file
8
Assets/Resources/Data/Items/Tower.asset.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ef628c3158b0ea34bb919ca105507009
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -33,7 +33,7 @@ namespace Controller
|
|||||||
|
|
||||||
data.WeaponsData.WeaponsList.ForEach(x => x.SetModifiedDamage(0));
|
data.WeaponsData.WeaponsList.ForEach(x => x.SetModifiedDamage(0));
|
||||||
|
|
||||||
ItemFabric itemFabric = new ItemFabric(data.ItemsData, SetUpItems());
|
ItemFabric itemFabric = new ItemFabric(data.ItemsData);
|
||||||
controllers.Add(itemFabric);
|
controllers.Add(itemFabric);
|
||||||
|
|
||||||
UIController uiController = new UIController(data.UIData);
|
UIController uiController = new UIController(data.UIData);
|
||||||
@ -86,7 +86,7 @@ namespace Controller
|
|||||||
|
|
||||||
private List<Type> SetUpItems()
|
private List<Type> SetUpItems()
|
||||||
{
|
{
|
||||||
return new List<Type>() { typeof(Building), typeof(AttackBonus), typeof(DefenceBonus) };
|
return new List<Type>() { typeof(Building), typeof(Bonus)};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,34 +10,27 @@ namespace Data
|
|||||||
public class ItemsData : ScriptableObject
|
public class ItemsData : ScriptableObject
|
||||||
{
|
{
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private List<ItemInfo> itemInfos;
|
private List<ItemInfos> items;
|
||||||
|
|
||||||
[SerializeField] private float fromTimeSpawn;
|
[SerializeField] private float fromTimeSpawn;
|
||||||
[SerializeField] private float toTimeSpawn;
|
[SerializeField] private float toTimeSpawn;
|
||||||
|
|
||||||
public List<ItemInfo> ItemInfos => itemInfos;
|
public List<ItemInfos> ItemInfos => items;
|
||||||
public (float from, float to) SpawnTime => (fromTimeSpawn, toTimeSpawn);
|
public (float from, float to) SpawnTime => (fromTimeSpawn, toTimeSpawn);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public struct ItemInfo
|
public struct ItemInfos
|
||||||
{
|
{
|
||||||
[SerializeField] private GameObject prefab;
|
[SerializeField] private Item item;
|
||||||
[SerializeField] private bool isInstantUse;
|
|
||||||
[SerializeField] private string type;
|
|
||||||
[SerializeField] private Sprite icon;
|
|
||||||
[SerializeField] private GameObject spawnablePrefab;
|
|
||||||
[SerializeField] private int[] values;
|
|
||||||
[SerializeField][Range(0,1)] private float spawnChance;
|
|
||||||
public GameObject Prefab => prefab;
|
|
||||||
public string Type => type;
|
|
||||||
|
|
||||||
public Sprite Icon => icon;
|
|
||||||
|
|
||||||
public GameObject SpawnablePrefab => spawnablePrefab;
|
[SerializeField][Range(0,1)] private float _spawnChance;
|
||||||
|
|
||||||
public bool IsInstanceUse => isInstantUse;
|
public Item Item => item;
|
||||||
public int[] Values => values;
|
|
||||||
public float SpawnChance => spawnChance;
|
|
||||||
|
public float SpawnChance => _spawnChance;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ namespace GameUI
|
|||||||
[SerializeField] private GameObject item;
|
[SerializeField] private GameObject item;
|
||||||
[SerializeField] private GameObject grid;
|
[SerializeField] private GameObject grid;
|
||||||
|
|
||||||
public Action<Item> OnItemInvoked;
|
public Action<Building> OnBuildingInvoked;
|
||||||
|
|
||||||
private List<Button> _buttons;
|
private List<Button> _buttons;
|
||||||
private Button[] _freeButtons;
|
private Button[] _freeButtons;
|
||||||
@ -66,23 +66,26 @@ namespace GameUI
|
|||||||
button.image.sprite = item.Icon;
|
button.image.sprite = item.Icon;
|
||||||
button.onClick.AddListener(() =>
|
button.onClick.AddListener(() =>
|
||||||
{
|
{
|
||||||
if (item.IsInstantUse)
|
switch (item)
|
||||||
{
|
{
|
||||||
button.onClick.RemoveAllListeners();
|
case Bonus _bonus:
|
||||||
item.InstanceInvoke();
|
|
||||||
for (int i = 0; i < _freeButtons.Length; i++)
|
|
||||||
{
|
{
|
||||||
if (_freeButtons[i] != null) continue;
|
button.onClick.RemoveAllListeners();
|
||||||
_freeButtons[i] = button;
|
_bonus.Invoke();
|
||||||
|
for (int i = 0; i < _freeButtons.Length; i++)
|
||||||
|
{
|
||||||
|
if (_freeButtons[i] != null) continue;
|
||||||
|
_freeButtons[i] = button;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
button.onClick.RemoveAllListeners();
|
||||||
|
button.gameObject.SetActive(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
button.onClick.RemoveAllListeners();
|
case Building _building:
|
||||||
button.gameObject.SetActive(false);
|
_building.Invoke(SwitchButton);
|
||||||
}
|
OnBuildingInvoked?.Invoke(_building);
|
||||||
else
|
break;
|
||||||
{
|
|
||||||
item.Invoke(SwitchButton);
|
|
||||||
OnItemInvoked?.Invoke(item);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Data;
|
|
||||||
using HexFiled;
|
|
||||||
|
|
||||||
namespace Items
|
|
||||||
{
|
|
||||||
public class AttackBonus : Item
|
|
||||||
{
|
|
||||||
public AttackBonus(ItemInfo data) : base(data)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Invoke(Action<Item> item)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void InstanceInvoke()
|
|
||||||
{
|
|
||||||
Unit.SetAttackBonus(Data.Values[0], Data.Values[1]);
|
|
||||||
Unit.UseItem(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void PlaceItem(HexCell cell)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
28
Assets/Scripts/Items/Bonus.cs
Normal file
28
Assets/Scripts/Items/Bonus.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using Data;
|
||||||
|
using HexFiled;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Items
|
||||||
|
{
|
||||||
|
public enum BonusType
|
||||||
|
{
|
||||||
|
Attack,
|
||||||
|
Defence
|
||||||
|
}
|
||||||
|
[CreateAssetMenu(fileName = "BonusItem", menuName = "Item/Bonus")]
|
||||||
|
public class Bonus : Item
|
||||||
|
{
|
||||||
|
[SerializeField] private float duration;
|
||||||
|
[SerializeField] private int value;
|
||||||
|
[SerializeField] private BonusType type;
|
||||||
|
public void Invoke()
|
||||||
|
{
|
||||||
|
Unit.SetUpBonus(duration, value, type);
|
||||||
|
Unit.UseItem(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Data;
|
using Data;
|
||||||
|
using DefaultNamespace;
|
||||||
using HexFiled;
|
using HexFiled;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@ -7,29 +8,23 @@ using Object = UnityEngine.Object;
|
|||||||
|
|
||||||
namespace Items
|
namespace Items
|
||||||
{
|
{
|
||||||
|
[CreateAssetMenu(fileName = "BuildingItem", menuName = "Item/Building")]
|
||||||
public class Building : Item
|
public class Building : Item
|
||||||
{
|
{
|
||||||
|
|
||||||
public Building(ItemInfo data) : base(data)
|
[SerializeField] private GameObject buildingPrefab;
|
||||||
{
|
|
||||||
|
|
||||||
}
|
public void Invoke(Action<Item> action)
|
||||||
|
|
||||||
public override void Invoke(Action<Item> action)
|
|
||||||
{
|
{
|
||||||
|
Unit.UseItem(this);
|
||||||
OnItemUsed += action;
|
OnItemUsed += action;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InstanceInvoke()
|
|
||||||
{
|
|
||||||
Unit.UseItem(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void PlaceItem(HexCell cell)
|
public void PlaceItem(HexCell cell)
|
||||||
{
|
{
|
||||||
Unit.UseItem(this);
|
Unit.UseItem(this);
|
||||||
var obj = Object.Instantiate(Data.SpawnablePrefab, cell.transform.position + Data.SpawnablePrefab.transform.position, Quaternion.identity);
|
var obj = SpawnHelper.Spawn(buildingPrefab, cell.transform.position + buildingPrefab.transform.position);
|
||||||
obj.GetComponent<TowerView>().SetUp(Unit.Color);
|
obj.GetComponent<TowerView>().SetUp(Unit.Color);
|
||||||
cell.Building = obj.GetComponent<TowerView>();
|
cell.Building = obj.GetComponent<TowerView>();
|
||||||
OnItemUsed?.Invoke(this);
|
OnItemUsed?.Invoke(this);
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Data;
|
|
||||||
using HexFiled;
|
|
||||||
|
|
||||||
namespace Items
|
|
||||||
{
|
|
||||||
public class DefenceBonus : Item
|
|
||||||
{
|
|
||||||
public DefenceBonus(ItemInfo data) : base(data)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Invoke(Action<Item> item)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void InstanceInvoke()
|
|
||||||
{
|
|
||||||
Unit.SetDefenceBonus(Data.Values[0], Data.Values[1]);
|
|
||||||
Unit.UseItem(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void PlaceItem(HexCell cell)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: c518da097b3645c491c6a4cc61b3d493
|
|
||||||
timeCreated: 1641382317
|
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Data;
|
using Data;
|
||||||
|
using DefaultNamespace;
|
||||||
using HexFiled;
|
using HexFiled;
|
||||||
using Units;
|
using Units;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -8,42 +9,30 @@ using Object = UnityEngine.Object;
|
|||||||
|
|
||||||
namespace Items
|
namespace Items
|
||||||
{
|
{
|
||||||
public abstract class Item : IDisposable
|
public abstract class Item : ScriptableObject
|
||||||
{
|
{
|
||||||
private GameObject _instance;
|
private GameObject _instance;
|
||||||
|
[SerializeField] private GameObject iconPrefab;
|
||||||
|
[SerializeField] private Sprite icon;
|
||||||
|
public Sprite Icon => icon;
|
||||||
|
public GameObject IconPrefab => iconPrefab;
|
||||||
|
|
||||||
protected ItemInfo Data;
|
|
||||||
protected Unit Unit;
|
protected Unit Unit;
|
||||||
protected Action<Item> OnItemUsed;
|
protected Action<Item> OnItemUsed;
|
||||||
|
|
||||||
public bool IsInstantUse => Data.IsInstanceUse;
|
|
||||||
public Sprite Icon => Data.Icon;
|
|
||||||
public UnitColor Color => Unit.Color;
|
public UnitColor Color => Unit.Color;
|
||||||
protected Item(ItemInfo data)
|
|
||||||
|
public GameObject Spawn(HexCell cell)
|
||||||
{
|
{
|
||||||
Data = data;
|
var obj = SpawnHelper.Spawn(iconPrefab, cell.transform.position + new Vector3(0, 1, 0));
|
||||||
|
obj.AddComponent<ItemView>().SetUp(this);
|
||||||
|
obj.AddComponent<CapsuleCollider>().isTrigger = true;
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PickUp(Unit unit)
|
public void PickUp(Unit unit)
|
||||||
{
|
{
|
||||||
Unit = unit;
|
Unit = unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameObject Spawn(HexCell cell)
|
|
||||||
{
|
|
||||||
_instance = Object.Instantiate(Data.Prefab, cell.transform.position + new Vector3(0, 1, 0),
|
|
||||||
Quaternion.identity);
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public abstract void Invoke(Action<Item> item);
|
|
||||||
public abstract void InstanceInvoke();
|
|
||||||
public abstract void PlaceItem(HexCell cell);
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Object.Destroy(_instance);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,15 +15,13 @@ namespace Items
|
|||||||
private ItemsData _data;
|
private ItemsData _data;
|
||||||
private List<HexCell> _openList;
|
private List<HexCell> _openList;
|
||||||
private List<Type> _itemTypes;
|
private List<Type> _itemTypes;
|
||||||
private Dictionary<string, ItemInfo> _itemInfos;
|
|
||||||
private float _spawnTime;
|
private float _spawnTime;
|
||||||
private float time;
|
private float time;
|
||||||
|
|
||||||
public ItemFabric(ItemsData data, List<Type> dictionary)
|
public ItemFabric(ItemsData data)
|
||||||
{
|
{
|
||||||
_itemInfos = new Dictionary<string, ItemInfo>();
|
|
||||||
data.ItemInfos.ForEach(info => { _itemInfos.Add(info.Type, info); });
|
|
||||||
_itemTypes = dictionary;
|
|
||||||
_data = data;
|
_data = data;
|
||||||
_openList = new List<HexCell>();
|
_openList = new List<HexCell>();
|
||||||
_spawnTime = Random.Range(data.SpawnTime.from, data.SpawnTime.to);
|
_spawnTime = Random.Range(data.SpawnTime.from, data.SpawnTime.to);
|
||||||
@ -55,36 +53,37 @@ namespace Items
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = GetWeightedType();
|
var i = GetWeightedItemIndex();
|
||||||
if (type == null)
|
if (i < 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var info = _itemInfos[type.ToString().Replace("Items.", "")];
|
|
||||||
var obj = (Item)Activator.CreateInstance(type, info);
|
|
||||||
|
|
||||||
var go = obj.Spawn(cell);
|
|
||||||
go.AddComponent<CapsuleCollider>().isTrigger = true;
|
_data.ItemInfos[i].Item.Spawn(cell);
|
||||||
var itemView = go.AddComponent<ItemView>();
|
cell.SetItem(_data.ItemInfos[i].Item);
|
||||||
itemView.SetUp(obj);
|
|
||||||
cell.SetItem(obj);
|
|
||||||
_spawnTime = Random.Range(_data.SpawnTime.from, _data.SpawnTime.to);
|
_spawnTime = Random.Range(_data.SpawnTime.from, _data.SpawnTime.to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type GetWeightedType()
|
private int GetWeightedItemIndex()
|
||||||
{
|
{
|
||||||
float randomNum = Random.Range(1, 101)/100f;
|
float randomNum = Random.Range(1, 101)/100f;
|
||||||
List<Type> possibleTypes = new List<Type>();
|
List<ItemInfos> possibleTypes = new List<ItemInfos>();
|
||||||
|
|
||||||
_itemTypes.ForEach(type =>
|
_data.ItemInfos.ForEach(item =>
|
||||||
{
|
{
|
||||||
if (_itemInfos[type.ToString().Replace("Items.", "")].SpawnChance >= randomNum)
|
if (item.SpawnChance >= randomNum)
|
||||||
{
|
{
|
||||||
possibleTypes.Add(type);
|
possibleTypes.Add(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return possibleTypes.Count > 0 ? possibleTypes[Random.Range(0, possibleTypes.Count - 1)] : null;
|
if (possibleTypes.Count > 0)
|
||||||
|
{
|
||||||
|
return Random.Range(0, possibleTypes.Count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
12
Assets/Scripts/SpawnHelper.cs
Normal file
12
Assets/Scripts/SpawnHelper.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace DefaultNamespace
|
||||||
|
{
|
||||||
|
public static class SpawnHelper
|
||||||
|
{
|
||||||
|
public static GameObject Spawn(GameObject gameObject, Vector3 pos)
|
||||||
|
{
|
||||||
|
return Object.Instantiate(gameObject, pos, Quaternion.identity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
Assets/Scripts/SpawnHelper.cs.meta
Normal file
3
Assets/Scripts/SpawnHelper.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6ec94f8447ef4582be47e726718b30b5
|
||||||
|
timeCreated: 1641866607
|
@ -23,7 +23,7 @@ namespace Chars
|
|||||||
private Vector2 _attackDircetion;
|
private Vector2 _attackDircetion;
|
||||||
private HexDirection _placeDirection;
|
private HexDirection _placeDirection;
|
||||||
private PlayerInventoryView _inventoryView;
|
private PlayerInventoryView _inventoryView;
|
||||||
private Item _itemToPlace;
|
private Building _itemToPlace;
|
||||||
private HexCell _cellToPlace;
|
private HexCell _cellToPlace;
|
||||||
|
|
||||||
|
|
||||||
@ -43,13 +43,13 @@ namespace Chars
|
|||||||
inventoryView.SetUpUI(unit.InventoryCapacity);
|
inventoryView.SetUpUI(unit.InventoryCapacity);
|
||||||
_unit.OnItemPickUp += PickUp;
|
_unit.OnItemPickUp += PickUp;
|
||||||
_inventoryView = inventoryView;
|
_inventoryView = inventoryView;
|
||||||
inventoryView.OnItemInvoked += AimPlaceItem;
|
inventoryView.OnBuildingInvoked += AimPlaceItem;
|
||||||
_placeJoystick.OnTouchDown += AimCanvas;
|
_placeJoystick.OnTouchDown += AimCanvas;
|
||||||
_placeJoystick.OnTouchUp += PlaceItem;
|
_placeJoystick.OnTouchUp += PlaceItem;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AimPlaceItem(Item item)
|
private void AimPlaceItem(Building item)
|
||||||
{
|
{
|
||||||
if (!_unit.IsBusy)
|
if (!_unit.IsBusy)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using Chars;
|
using Chars;
|
||||||
using Data;
|
using Data;
|
||||||
using DefaultNamespace;
|
using DefaultNamespace;
|
||||||
@ -65,7 +66,22 @@ namespace Units
|
|||||||
_isCapturing = false;
|
_isCapturing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetAttackBonus(int duration, int value)
|
public void SetUpBonus(float duration, int value, BonusType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case BonusType.Attack:
|
||||||
|
SetAttackBonus(duration, value);
|
||||||
|
break;
|
||||||
|
case BonusType.Defence:
|
||||||
|
SetDefenceBonus(duration, value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetAttackBonus(float duration, int value)
|
||||||
{
|
{
|
||||||
TimerHelper.Instance.StartTimer(StopAttackBonus, duration);
|
TimerHelper.Instance.StartTimer(StopAttackBonus, duration);
|
||||||
_weapon.SetModifiedDamage(value);
|
_weapon.SetModifiedDamage(value);
|
||||||
@ -76,7 +92,7 @@ namespace Units
|
|||||||
_weapon.SetModifiedDamage(0);
|
_weapon.SetModifiedDamage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetDefenceBonus(int duration, int value)
|
private void SetDefenceBonus(float duration, int value)
|
||||||
{
|
{
|
||||||
TimerHelper.Instance.StartTimer(StopDefenceBonus, duration);
|
TimerHelper.Instance.StartTimer(StopDefenceBonus, duration);
|
||||||
_defenceBonus = value;
|
_defenceBonus = value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user