Added items, inventory, basic inv mechanics and art, added item comparison, v1.3.0

This commit is contained in:
Nicola Sovic 2022-06-30 22:31:41 +02:00
parent cbedc285f1
commit 801983504d
44 changed files with 5538 additions and 18 deletions

Binary file not shown.

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f5735f0695164a8418fb8efb1bced054
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 549851b5913ff644dafd992e0944f03d
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: dd25d91a28ea30248a46bd2bb0c89b22
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 44e8241229d56c44394249690f95b37f
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8ef059b8e63eb14428e2096ed418b680
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ba51d33c22f383e478535934f5317147
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,96 @@
fileFormatVersion: 2
guid: 9d498dbee95788245a06def264ae3b16
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,96 @@
fileFormatVersion: 2
guid: 593835406b21e5e4687d705e92f57916
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,96 @@
fileFormatVersion: 2
guid: 5f308d204b3fbf14ba20f736cdb40a4d
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

167
Assets/Prefabs/slot.prefab Normal file
View File

@ -0,0 +1,167 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &206628748623723552
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 206628748623723553}
- component: {fileID: 206628748623723559}
- component: {fileID: 206628748623723558}
- component: {fileID: 206628748623723556}
- component: {fileID: 206628748623723557}
m_Layer: 5
m_Name: slot
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &206628748623723553
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 206628748623723552}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.075, y: 0.675}
m_AnchorMax: {x: 0.175, y: 0.975}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &206628748623723559
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 206628748623723552}
m_CullTransparentMesh: 1
--- !u!114 &206628748623723558
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 206628748623723552}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!114 &206628748623723556
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 206628748623723552}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b661b52d4ccd19649bb6a1a5f1d9b893, type: 3}
m_Name:
m_EditorClassIdentifier:
itemRemoved: 000000
place: 9
--- !u!114 &206628748623723557
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 206628748623723552}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0b148fe25e99eb48b9724523833bab1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Delegates:
- eventID: 0
callback:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 206628748623723556}
m_TargetAssemblyTypeName: Assets.Scripts.InventorySlot, Assembly-CSharp
m_MethodName: showTooltip
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- eventID: 1
callback:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 206628748623723556}
m_TargetAssemblyTypeName: Assets.Scripts.InventorySlot, Assembly-CSharp
m_MethodName: hideTooltip
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- eventID: 5
callback:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 206628748623723556}
m_TargetAssemblyTypeName: Assets.Scripts.InventorySlot, Assembly-CSharp
m_MethodName: OnMouseDrag
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- eventID: 6
callback:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 206628748623723556}
m_TargetAssemblyTypeName: Assets.Scripts.InventorySlot, Assembly-CSharp
m_MethodName: OnMouseUp
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6561ab2146fa2534cb13d1da79d00a97
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -114,6 +114,12 @@ namespace Assets.Scripts
uihandler.switchPauseMenu(); uihandler.switchPauseMenu();
} }
public void switchInventory()
{
audioHandler.playButtonClick();
uihandler.switchInventory();
}
public void saveGame() public void saveGame()
{ {
audioHandler.playButtonClick(); audioHandler.playButtonClick();

View File

@ -64,6 +64,10 @@ public class Controls : MonoBehaviour
{ {
uihandler.switchQuestLog(); uihandler.switchQuestLog();
} }
else if (Input.GetKeyDown(KeyCode.I))
{
uihandler.switchInventory();
}
} }
if (Input.GetKeyDown(KeyCode.Escape)) if (Input.GetKeyDown(KeyCode.Escape))

View File

@ -121,6 +121,11 @@ namespace Assets.Scripts
return slime.getExperience(); return slime.getExperience();
} }
public Item getItem()
{
return slime.getItem();
}
public string saveEnemy() public string saveEnemy()
{ {
string result = ""; string result = "";

View File

@ -61,7 +61,7 @@ public class Fight : MonoBehaviour
playerDamage = player.GetComponent<Player>().castSkill(skillnumber); playerDamage = player.GetComponent<Player>().castSkill(skillnumber);
} }
player.GetComponent<Player>().reduceCooldown(skillnumber); player.GetComponent<Player>().reduceCooldown(skillnumber);
player.GetComponent<Player>().regainSecondary(2); player.GetComponent<Player>().regainSecondary();
bool isDead = enemy.GetComponent<Enemy>().takeDamage(playerDamage); bool isDead = enemy.GetComponent<Enemy>().takeDamage(playerDamage);
if (isDead) if (isDead)
{ {
@ -73,6 +73,7 @@ public class Fight : MonoBehaviour
tile.GetComponent<Tile>().enemyKilled(enemy); tile.GetComponent<Tile>().enemyKilled(enemy);
player.GetComponent<Player>().enemyKilled(); player.GetComponent<Player>().enemyKilled();
player.GetComponent<Player>().gainExperience(enemy.GetComponent<Enemy>().getExperience()); player.GetComponent<Player>().gainExperience(enemy.GetComponent<Enemy>().getExperience());
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(enemy.GetComponent<Enemy>().getItem());
} }
else else
{ {

181
Assets/Scripts/Inventory.cs Normal file
View File

@ -0,0 +1,181 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Assets.Scripts
{
public class Inventory : MonoBehaviour
{
public GameObject head;
public GameObject chest;
public GameObject shoulders;
public GameObject feet;
public GameObject ring;
public GameObject amulet;
public GameObject hands;
public GameObject leftHand;
public GameObject rightHand;
public GameObject[] bags;
public GameObject[] slots;
public int currentBag = -1;
GameObject startDrag;
// Start is called before the first frame update
void Start()
{
changeCurrentBag(0);
}
// Update is called once per frame
void Update()
{
checkInventoryColors();
checkEquipColors();
}
public void addItem(Item item)
{
if (item != null)
{
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("SUCCESS;You got an item!");
bool itemAdded = false;
for (int i = 0; i < bags.Length; i++)
{
for (int j = 0; j < slots.Length; j++)
{
if (slots[j].GetComponent<InventorySlot>().getItem() == null)
{
slots[j].GetComponent<InventorySlot>().setItem(item);
itemAdded = true;
slots[j].GetComponent<RawImage>().color = Color.red;
break;
}
}
if (itemAdded)
{
break;
}
}
}
}
public void changeCurrentBag(int index)
{
if (currentBag != -1)
{
bags[currentBag].GetComponent<RawImage>().color = Color.white;
}
currentBag = index;
bags[currentBag].GetComponent<RawImage>().color = Color.cyan;
checkInventoryColors();
foreach(GameObject slot in slots)
{
slot.GetComponent<InventorySlot>().updateCurrentBag(currentBag);
}
}
private void checkInventoryColors()
{
for (int i = 0; i < slots.Length; i++)
{
if (slots[i].GetComponent<InventorySlot>().getItem() != null)
{
slots[i].GetComponent<RawImage>().color = Color.red;
}
else
{
slots[i].GetComponent<RawImage>().color = Color.white;
}
}
}
private void checkEquipColors()
{
GameObject slot = head;
for (int i = 0; i < 9; i++)
{
switch (i)
{
case 0:
slot = head;
break;
case 1:
slot = rightHand;
break;
case 2:
slot = leftHand;
break;
case 3:
slot = hands;
break;
case 4:
slot = amulet;
break;
case 5:
slot = feet;
break;
case 6:
slot = shoulders;
break;
case 7:
slot = chest;
break;
case 8:
slot = ring;
break;
}
if (slot.GetComponent<InventorySlot>().getEquip() != null)
{
slot.GetComponent<RawImage>().color = Color.red;
}
else
{
slot.GetComponent<RawImage>().color = Color.white;
}
}
}
public void setDrag(GameObject slot)
{
startDrag = slot;
}
public GameObject getDrag()
{
return startDrag;
}
public Item getEquip(ItemPlace place)
{
switch (place)
{
case ItemPlace.SHIELD:
return leftHand.GetComponent<InventorySlot>().getEquip();
case ItemPlace.WEAPON:
return rightHand.GetComponent<InventorySlot>().getEquip();
case ItemPlace.HELMET:
return head.GetComponent<InventorySlot>().getEquip();
case ItemPlace.BOOTS:
return feet.GetComponent<InventorySlot>().getEquip();
case ItemPlace.SHOULDER:
return shoulders.GetComponent<InventorySlot>().getEquip();
case ItemPlace.AMULET:
return amulet.GetComponent<InventorySlot>().getEquip();
case ItemPlace.RING:
return ring.GetComponent<InventorySlot>().getEquip();
case ItemPlace.ARMOR:
return chest.GetComponent<InventorySlot>().getEquip();
case ItemPlace.GLOVES:
return hands.GetComponent<InventorySlot>().getEquip();
default:
return null;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 78a3db482922b1c4385629b9511c9647
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,158 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Assets.Scripts
{
public class InventorySlot : MonoBehaviour
{
TooltipHandler tooltip;
Item[] items = new Item[3];
public bool[] itemRemoved = {false, false, false};
int currentBag = 0;
public ItemPlace place;
Item equip;
private void Start()
{
tooltip = GameObject.Find("TooltipHandler").GetComponent<TooltipHandler>();
}
public void updateCurrentBag(int currentBag)
{
this.currentBag = currentBag;
}
public void setItem(Item item)
{
items[currentBag] = item;
itemRemoved[currentBag] = false;
}
public Item getItem()
{
return items[currentBag];
}
public void removeItem()
{
items[currentBag] = null;
itemRemoved[currentBag] = true;
}
public void showTooltip()
{
if (place == ItemPlace.BAG)
{
if (items[currentBag] != null)
{
string text = items[currentBag].getDisplayText();
Item equip = GameObject.Find("Inventory").GetComponent<Inventory>().getEquip(items[currentBag].getPlace());
if (equip != null)
{
text = "(Current)\r\n" + equip.getDisplayText() + "----------\r\n" + text;
}
tooltip.showTooltip(text);
}
}
else
{
if (equip != null)
{
tooltip.showTooltip(equip.getDisplayText());
}
}
}
public void hideTooltip()
{
tooltip.hideToolTip();
}
public void onClick()
{
removeItem();
tooltip.hideToolTip();
}
public void OnMouseDrag()
{
GameObject.Find("Inventory").GetComponent<Inventory>().setDrag(gameObject);
}
public void OnMouseUp()
{
GameObject startDrag = GameObject.Find("Inventory").GetComponent<Inventory>().getDrag();
Item item;
bool isSwap = false;
if (startDrag.GetComponent<InventorySlot>().place == ItemPlace.BAG)
{
item = startDrag.GetComponent<InventorySlot>().getItem();
}
else
{
item = startDrag.GetComponent<InventorySlot>().getEquip();
}
if (item != null)
{
if (place != item.getPlace() && place != ItemPlace.BAG)
{
return;
}
if (place == ItemPlace.BAG)
{
if (items[currentBag] != null)
{
startDrag.GetComponent<InventorySlot>().setItem(items[currentBag]);
isSwap = true;
}
setItem(item);
}
else
{
if (equip != null)
{
if (startDrag.GetComponent<InventorySlot>().place == ItemPlace.BAG)
{
startDrag.GetComponent<InventorySlot>().setItem(equip);
isSwap = true;
}
else
{
return;
}
}
setEquip(item);
}
if (!isSwap)
{
if (startDrag.GetComponent<InventorySlot>().place != ItemPlace.BAG)
{
startDrag.GetComponent<InventorySlot>().removeEquip();
}
else
{
startDrag.GetComponent<InventorySlot>().removeItem();
}
}
}
}
public Item getEquip()
{
return equip;
}
public void setEquip(Item item)
{
equip = item;
}
public void removeEquip()
{
equip = null;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b661b52d4ccd19649bb6a1a5f1d9b893
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

204
Assets/Scripts/Item.cs Normal file
View File

@ -0,0 +1,204 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Assets.Scripts
{
public class Item
{
private System.Random rand = new System.Random();
ItemRarity rarity;
ItemPlace place;
string itemName;
Dictionary<string, int> attributes;
public Item(int luck)
{
attributes = new Dictionary<string, int>();
int numberOfAttributes = 1;
calculateRarity(luck);
if (rarity > ItemRarity.COMMON)
{
numberOfAttributes = 2;
}
if (rarity > ItemRarity.RARE)
{
numberOfAttributes = 3;
}
if (rarity == ItemRarity.LEGENDARY)
{
numberOfAttributes = 0;
}
calculateAttributes(luck, numberOfAttributes);
place = (ItemPlace)rand.Next(9);
if (itemName != null)
{
itemName = rarity.ToString() + " " + place.ToString() + " of " + itemName;
}
else
{
itemName = rarity.ToString() + " " + place.ToString();
}
itemName = itemName.ToLower();
itemName = char.ToUpper(itemName[0]) + itemName.Substring(1);
}
private void calculateRarity(int luck)
{
int number = rand.Next(101);
if (number + luck < 74)
{
rarity = ItemRarity.COMMON;
}
else if (number + luck >= 75 && number + luck < 104)
{
rarity = ItemRarity.RARE;
}
else if (number + luck >= 105 && number + luck < 113)
{
rarity = ItemRarity.EPIC;
}
else if (number + luck >= 114)
{
rarity = ItemRarity.LEGENDARY;
}
}
private void calculateAttributes(int luck, int numberOfAttributes)
{
if (numberOfAttributes != 0)
{
int[] indexes = new int[numberOfAttributes];
int index;
for (int i = 0; i < numberOfAttributes; i++)
{
index = calculateIndex(indexes);
switch (index)
{
case 0:
if (i == 0)
{
itemName = "luck";
}
attributes.Add("LCK", Mathf.RoundToInt((float)(5 - (2 * i) + luck * 0.2)));
break;
case 1:
if (i == 0)
{
itemName = "intelligence";
}
attributes.Add("INT", Mathf.RoundToInt((float)(5 - (2 * i) + luck * 0.2)));
break;
case 2:
if (i == 0)
{
itemName = "dexterity";
}
attributes.Add("DEX", Mathf.RoundToInt((float)(5 - (2 * i) + luck * 0.2)));
break;
case 3:
if (i == 0)
{
itemName = "strength";
}
attributes.Add("STR", Mathf.RoundToInt((float)(5 - (2 * i) + luck * 0.2)));
break;
case 4:
if (i == 0)
{
itemName = "health";
}
attributes.Add("HP", Mathf.RoundToInt((float)(5 - (2 * i) + luck * 0.2)));
break;
case 5:
if (i == 0)
{
itemName = "mana";
}
attributes.Add("MP", Mathf.RoundToInt((float)(5 - (2 * i) + luck * 0.2)));
break;
case 6:
if (i == 0)
{
itemName = "health regeneration";
}
attributes.Add("HPR", Mathf.RoundToInt((float)(5 - (2 * i) + luck * 0.2)));
break;
case 7:
if (i == 0)
{
itemName = "mana regeneration";
}
attributes.Add("MPR", Mathf.RoundToInt((float)(5 - (2 * i) + luck * 0.2)));
break;
}
indexes[0] = index;
}
}
else
{
attributes.Add("MPR", Mathf.RoundToInt((float)(5 + luck * 0.2)));
attributes.Add("HPR", Mathf.RoundToInt((float)(5 + luck * 0.2)));
attributes.Add("MP", Mathf.RoundToInt((float)(5 + luck * 0.2)));
attributes.Add("HP", Mathf.RoundToInt((float)(5 + luck * 0.2)));
attributes.Add("STR", Mathf.RoundToInt((float)(5 + luck * 0.2)));
attributes.Add("DEX", Mathf.RoundToInt((float)(5 + luck * 0.2)));
attributes.Add("INT", Mathf.RoundToInt((float)(5 + luck * 0.2)));
attributes.Add("LCK", Mathf.RoundToInt((float)(5 + luck * 0.2)));
}
}
private int calculateIndex(int[] indexes)
{
int counter = 0;
int index = 0;
while (true)
{
index = rand.Next(8);
counter = 0;
for (int j = 0; j < indexes.Length; j++)
{
if (indexes[j] == index)
{
counter++;
break;
}
}
if (counter == 0)
{
break;
}
}
return index;
}
public string getName()
{
return itemName;
}
public ItemPlace getPlace()
{
return place;
}
public string getDisplayText()
{
string displayText = "";
displayText = displayText + itemName + "\r\n";
if (rarity == ItemRarity.LEGENDARY)
{
displayText = displayText + "All attributes: +" + attributes["STR"];
}
else
{
foreach (string key in attributes.Keys)
{
displayText = displayText + key + ": +" + attributes[key] + "\r\n";
}
}
return displayText;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1538bd0f82fb96a43bba47a68a430dcd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1ea385be8a0d614459d7ca608d06b10d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts
{
public enum ItemPlace
{
HELMET,
SHOULDER,
WEAPON,
SHIELD,
GLOVES,
RING,
AMULET,
ARMOR,
BOOTS,
BAG
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a194de2ca78d01048924703904253d86
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts
{
public enum ItemRarity
{
COMMON,
RARE,
EPIC,
LEGENDARY
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bb1c2cc6603c0684cb04dc2d22ac95b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 648f691b06a71134d8ff2a5599a25c30
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -29,8 +29,11 @@ namespace Assets.Scripts
int dexterity; int dexterity;
int intelligence; int intelligence;
int level; int level;
int luck;
int experience; int experience;
int maxExperience; int maxExperience;
int healthRegen;
int secondaryRegen;
BasicRace race; BasicRace race;
BasicClass role; BasicClass role;
BasicSkill[] skills = new BasicSkill[3]; BasicSkill[] skills = new BasicSkill[3];
@ -41,6 +44,13 @@ namespace Assets.Scripts
int killcount = -1; int killcount = -1;
int difficulty = 0; int difficulty = 0;
private void OnEnable()
{
#if UNITY_EDITOR
SceneHandler.switchGameToMenu();
#endif
}
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
@ -67,7 +77,10 @@ namespace Assets.Scripts
intelligence = 5; intelligence = 5;
experience = 0; experience = 0;
maxExperience = 10; maxExperience = 10;
healthRegen = 30 / (difficulty + 1);
secondaryRegen = 5;
level = 0; level = 0;
luck = 20 - (difficulty * 5);
this.race = race; this.race = race;
this.race.applyBonus(this); this.race.applyBonus(this);
this.role = role; this.role = role;
@ -117,7 +130,10 @@ namespace Assets.Scripts
intelligence = 5; intelligence = 5;
experience = 0; experience = 0;
maxExperience = 10; maxExperience = 10;
healthRegen = 30 / (difficulty + 1);
secondaryRegen = 5;
level = 0; level = 0;
luck = 20 - (difficulty * 5);
this.race.applyBonus(this); this.race.applyBonus(this);
this.role.applyBonus(this); this.role.applyBonus(this);
this.difficulty = PlayerPrefs.GetInt("difficulty"); this.difficulty = PlayerPrefs.GetInt("difficulty");
@ -189,7 +205,7 @@ namespace Assets.Scripts
if (now.AddSeconds(10).CompareTo(DateTime.Now) <= 0) if (now.AddSeconds(10).CompareTo(DateTime.Now) <= 0)
{ {
now = DateTime.Now; now = DateTime.Now;
regainSecondary(5); regainSecondary();
healPlayer(); healPlayer();
} }
} }
@ -200,9 +216,9 @@ namespace Assets.Scripts
} }
} }
public void regainSecondary(int amount) public void regainSecondary()
{ {
secondary = secondary + amount; secondary = secondary + secondaryRegen;
if (secondary >= maxSecondary) if (secondary >= maxSecondary)
{ {
secondary = maxSecondary; secondary = maxSecondary;
@ -211,7 +227,7 @@ namespace Assets.Scripts
private void healPlayer() private void healPlayer()
{ {
health = health + 30 / (difficulty + 1); health = health + healthRegen;
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S)) if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S))
{ {
health = health + 5; health = health + 5;
@ -300,7 +316,7 @@ namespace Assets.Scripts
public int[] getStats() public int[] getStats()
{ {
int[] result = { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience, points}; int[] result = { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience, points, luck};
return result; return result;
} }
@ -463,6 +479,7 @@ namespace Assets.Scripts
uihandler.showMessage("SUCCESS;You gained a level!"); uihandler.showMessage("SUCCESS;You gained a level!");
points = points + 3; points = points + 3;
audioHandler.playLevelUp(); audioHandler.playLevelUp();
luck = luck + 2;
} }
} }
@ -589,8 +606,11 @@ namespace Assets.Scripts
result = result + FileHandler.generateJSON("race", "\"" + race.racename + "\"") + ",\r\n"; result = result + FileHandler.generateJSON("race", "\"" + race.racename + "\"") + ",\r\n";
result = result + FileHandler.generateJSON("role", "\"" + role.classname + "\"") + ",\r\n"; result = result + FileHandler.generateJSON("role", "\"" + role.classname + "\"") + ",\r\n";
result = result + FileHandler.generateJSON("points", points) + ",\r\n"; result = result + FileHandler.generateJSON("points", points) + ",\r\n";
result = result + FileHandler.generateJSON("healthRegen", healthRegen) + ",\r\n";
result = result + FileHandler.generateJSON("secondaryRegen", secondaryRegen) + ",\r\n";
result = result + FileHandler.generateJSON("isDodging", "\"" + isDodging + "\"") + ",\r\n"; result = result + FileHandler.generateJSON("isDodging", "\"" + isDodging + "\"") + ",\r\n";
result = result + FileHandler.generateJSON("killcount", killcount) + ",\r\n"; result = result + FileHandler.generateJSON("killcount", killcount) + ",\r\n";
result = result + FileHandler.generateJSON("luck", luck) + ",\r\n";
result = result + FileHandler.generateJSON("difficulty", difficulty); result = result + FileHandler.generateJSON("difficulty", difficulty);
return result; return result;
} }
@ -611,6 +631,9 @@ namespace Assets.Scripts
loadRole(json["role"].ToString()); loadRole(json["role"].ToString());
loadRace(json["race"].ToString()); loadRace(json["race"].ToString());
points = (int)json["points"]; points = (int)json["points"];
luck = (int)json["luck"];
healthRegen = (int)json["healthRegen"];
secondaryRegen = (int)json["secondaryRegen"];
isDodging = bool.Parse(json["isDodging"].ToString()); isDodging = bool.Parse(json["isDodging"].ToString());
killcount = (int)json["killcount"]; killcount = (int)json["killcount"];
difficulty = (int)json["difficulty"]; difficulty = (int)json["difficulty"];

View File

@ -9,7 +9,7 @@ namespace Assets.Scripts
{ {
public class SceneHandler : MonoBehaviour public class SceneHandler : MonoBehaviour
{ {
static bool sceneSwitched = false;
private void OnEnable() private void OnEnable()
{ {
SceneManager.sceneLoaded += OnSceneLoaded; SceneManager.sceneLoaded += OnSceneLoaded;
@ -51,6 +51,15 @@ namespace Assets.Scripts
SceneManager.LoadScene("GameScene"); SceneManager.LoadScene("GameScene");
} }
public static void switchGameToMenu()
{
if (!sceneSwitched)
{
SceneManager.LoadScene("MenuScene");
sceneSwitched = true;
}
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode) private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{ {
if (scene.name == "GameScene") if (scene.name == "GameScene")

View File

@ -18,10 +18,11 @@ namespace Assets.Scripts.Slimes
protected int intelligence; protected int intelligence;
protected int level; protected int level;
protected int experience; protected int experience;
protected Item item;
public BasicSlime(Player player) public BasicSlime(Player player)
{ {
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, playerlevel}; //health,maxHealth,secondary,maxSecondary,strength,dexterity,intelligence,level,experience,maxExperience,points,luck
int[] playerStats = player.getStats(); int[] playerStats = player.getStats();
maxHealth = playerStats[1]; maxHealth = playerStats[1];
health = maxHealth; health = maxHealth;
@ -32,6 +33,10 @@ namespace Assets.Scripts.Slimes
intelligence = playerStats[6]; intelligence = playerStats[6];
experience = (int)(10 + playerStats[7] * 2.5f); experience = (int)(10 + playerStats[7] * 2.5f);
level = playerStats[7]; level = playerStats[7];
if (new System.Random().Next(100) + 1 < 1000)//50 + playerStats[11])
{
item = new Item(playerStats[11]);
}
} }
public BasicSlime(JToken json) public BasicSlime(JToken json)
@ -95,6 +100,11 @@ namespace Assets.Scripts.Slimes
return experience; return experience;
} }
public Item getItem()
{
return item;
}
public string saveSlime() public string saveSlime()
{ {
string result = ""; string result = "";

View File

@ -24,6 +24,7 @@ namespace Assets.Scripts
public GameObject tooltip; public GameObject tooltip;
public GameObject tutorial; public GameObject tutorial;
public GameObject buttonsHUD; public GameObject buttonsHUD;
public GameObject inventory;
public GameObject waterLayer; public GameObject waterLayer;
public UIState state; public UIState state;
@ -80,7 +81,7 @@ namespace Assets.Scripts
public bool canPlayerMove() public bool canPlayerMove()
{ {
if (state == UIState.GAME || state == UIState.CHARACTER || state == UIState.QUEST) if (state == UIState.GAME || state == UIState.CHARACTER || state == UIState.QUEST || state == UIState.INVENTORY)
{ {
return true; return true;
} }
@ -141,6 +142,31 @@ namespace Assets.Scripts
state = UIState.GAME; state = UIState.GAME;
} }
public void switchInventory()
{
if (state == UIState.INVENTORY)
{
closeInventory();
}
else
{
openInventory();
}
}
public void openInventory()
{
hideOtherElements(inventory);
state = UIState.INVENTORY;
}
public void closeInventory()
{
inventory.transform.localScale = new Vector3(0, 0, 0);
showHUD();
state = UIState.GAME;
}
public void openFight() public void openFight()
{ {
GameObject.Find("txtRounds").GetComponent<Text>().text = "-1"; GameObject.Find("txtRounds").GetComponent<Text>().text = "-1";

View File

@ -16,6 +16,7 @@ namespace Assets.Scripts
PAUSE, PAUSE,
PAUSEOPTIONS, PAUSEOPTIONS,
TUTORIAL, TUTORIAL,
QUEST QUEST,
INVENTORY
} }
} }

View File

@ -18,10 +18,10 @@ EditorUserSettings:
value: 22424703114646680e0b0227036c72111f19352f223d68252320092a value: 22424703114646680e0b0227036c72111f19352f223d68252320092a
flags: 0 flags: 0
RecentlyUsedScenePath-4: RecentlyUsedScenePath-4:
value: 22424703114646680e0b0227036c78111b122b292926237e38271427fb value: 22424703114646680e0b0227036c721518022b292926237e38271427fb
flags: 0 flags: 0
RecentlyUsedScenePath-5: RecentlyUsedScenePath-5:
value: 22424703114646680e0b0227036c721518022b292926237e38271427fb value: 22424703114646680e0b0227036c78111b122b292926237e38271427fb
flags: 0 flags: 0
vcSharedLogLevel: vcSharedLogLevel:
value: 0d5e400f0650 value: 0d5e400f0650

View File

@ -21,9 +21,9 @@
"world": { "world": {
"cityAmount": 5, "cityAmount": 5,
"maxCityAmount": 5, "maxCityAmount": 5,
"currentTile": "-1/0/0", "currentTile": "0/0/0",
"map": { "map": {
"tile0": "./save/tile0.json"
} }
} }
} }