Skip to content

Commit

Permalink
feat: Battery 아이템 수집 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarleter99 authored Apr 1, 2024
1 parent 83d66d3 commit 586a91b
Show file tree
Hide file tree
Showing 19 changed files with 246 additions and 132 deletions.
2 changes: 1 addition & 1 deletion Client/Assets/Resources/Datas/ExcelData/ItemData.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DataId,Name
201000,ItemA
201000,Battery
2 changes: 1 addition & 1 deletion Client/Assets/Resources/Datas/JsonData/ItemData.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"items": [
{
"DataId": 201000,
"Name": "ItemA"
"Name": "Battery"
}
]
}
15 changes: 12 additions & 3 deletions Client/Assets/Scripts/Contents/Item/BaseItem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
using Fusion;
using Data;
using Fusion;

public abstract class BaseItem
{
public Crew Owner { get; set; }
public int DataId { get; protected set; }
public ItemData ItemData { get; protected set; }
public Define.ItemType ItemType { get; set; }

public abstract bool CheckAndUseItem();
public virtual void SetInfo(int templateId)
{
DataId = templateId;
ItemData = Managers.DataMng.ItemDataDict[templateId];
}

public abstract bool CheckAndUseItem(Crew crew);

[Rpc(RpcSources.StateAuthority, RpcTargets.All)]
protected abstract void Rpc_Use();
Expand Down
10 changes: 3 additions & 7 deletions Client/Assets/Scripts/Contents/Item/Battery.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using Fusion;

public class Battery : BaseItem
public class Battery : BaseItem
{
public override bool CheckAndUseItem()
public override bool CheckAndUseItem(Crew crew)
{
Rpc_Use();
return true;
return false;
}

[Rpc(RpcSources.StateAuthority, RpcTargets.All)]
protected override void Rpc_Use()
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

public abstract class BaseInteractable : NetworkBehaviour
{
public virtual string InteractDescription { get; set; }
[Networked] public NetworkString<_16> InteractDescription { get; set; }

public abstract bool IsInteractable(Creature creature);
public abstract bool IsInteractable(Creature creature, bool isDoInteract);
public abstract void Interact(Creature creature);

public abstract void PlayInteractAnimation();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Fusion;
using UnityEngine;

public abstract class BaseItemObject : BaseInteractable
{
public Define.ItemType ItemType { get; protected set; }

public override string InteractDescription => $"Get {ItemType}";
public int DataId { get; protected set; }

public override void Spawned()
{
Expand All @@ -11,18 +12,41 @@ public override void Spawned()

protected abstract void Init();

public override bool IsInteractable(Creature creature)
public override bool IsInteractable(Creature creature, bool isDoInteract)
{
return creature is Crew;
if (creature.CreatureType == Define.CreatureType.Alien)
return false;

creature.IngameUI.InteractInfoUI.Show(InteractDescription.ToString());

if (!(creature.CreatureState == Define.CreatureState.Idle || creature.CreatureState == Define.CreatureState.Move))
return false;

if (!((Crew)creature).Inventory.CheckCanGetItem())
return false;

if (isDoInteract)
Interact(creature);

return true;
}

public override void Interact(Creature creature)
{
((Crew)creature).Inventory.CheckAndGetItem(ItemType);
PlayInteractAnimation();
Rpc_InteractComplete();

((Crew)creature).Inventory.GetItem(DataId);
}

[Rpc(RpcSources.All, RpcTargets.All)]
public virtual void Rpc_InteractComplete()
{
gameObject.SetActive(false);
}

public override void PlayInteractAnimation()
{
// TODO

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
protected override void Init()
{
ItemType = Define.ItemType.Battery;
DataId = Define.ITEM_Battery_ID;

InteractDescription = "GET BATTERY";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public abstract class BaseWorkStation : BaseInteractable
[Networked] public NetworkBool CanRememberWork { get; set; }
[Networked] public NetworkBool CanCollaborate { get; set; }
[Networked] public NetworkBool IsCompleted { get; set; }
[Networked] public NetworkString<_16> WorkingDescription { get; set; }

[Networked, Capacity(3)] public NetworkLinkedList<NetworkId> CurrentWorkers { get; }
public Creature MyWorker { get; protected set; }
Expand All @@ -26,30 +25,39 @@ protected virtual void Init()
CurrentWorkAmount = 0f;
}

public override bool IsInteractable(Creature creature)
public override bool IsInteractable(Creature creature, bool isDoInteract)
{
if (creature.CreatureType == Define.CreatureType.Alien)
return false;

if (!CanUseAgain && IsCompleted)
return false;

creature.IngameUI.InteractInfoUI.Show(InteractDescription.ToString());

if (CurrentWorkers.Count >= 3 || (!CanCollaborate && CurrentWorkers.Count >= 1))
return false;

if (!(creature.CreatureState == Define.CreatureState.Idle || creature.CreatureState == Define.CreatureState.Move))
return false;

if (isDoInteract)
Interact(creature);

return true;
}

public override void Interact(Creature creature)
{
MyWorker = creature;
MyWorker.IngameUI.WorkProgressBarUI.Show(WorkingDescription.ToString(), TotalWorkAmount);
MyWorker.IngameUI.InteractInfoUI.Hide();
MyWorker.CreatureState = Define.CreatureState.Interact;
MyWorker.CreaturePose = Define.CreaturePose.Stand;
MyWorker.CurrentWorkStation = this;
MyWorker.IngameUI.WorkProgressBarUI.Show(InteractDescription.ToString(), TotalWorkAmount);

Rpc_AddWorker(MyWorker.NetworkObject.Id);
PlayInteractAnimation();
Rpc_AddWorker(MyWorker.NetworkObject.Id);

StartCoroutine(CoWorkProgress());
}
Expand All @@ -64,6 +72,16 @@ public void MyWorkInterrupt()
Debug.Log($"{MyWorker.NetworkObject.Id}: Interrupt Work"); // TODO - Test code
}

public virtual void WorkComplete()
{
if (MyWorker.CreatureType == Define.CreatureType.Crew)
Rpc_CrewWorkComplete();
else if (MyWorker.CreatureType == Define.CreatureType.Alien)
Rpc_AlienWorkComplete();
else
Debug.LogError("Failed to WorkComplete");
}

[Rpc(RpcSources.All, RpcTargets.StateAuthority)]
protected void Rpc_AddWorker(NetworkId networkId)
{
Expand Down Expand Up @@ -111,12 +129,6 @@ protected virtual IEnumerator CoWorkProgress()
}

MyWorkInterrupt();

if (MyWorker.CreatureType == Define.CreatureType.Crew)
Rpc_CrewWorkComplete();
else if (MyWorker.CreatureType == Define.CreatureType.Alien)
Rpc_AlienWorkComplete();
else
Debug.LogError("Failed to WorkProgress");
WorkComplete();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
public class BatteryCharger : BaseWorkStation
{
public Crew MyCrew => (Crew)MyWorker;

protected override void Init()
{
base.Init();

InteractDescription = "USE COMPUTER";

CanUseAgain = true;
CanRememberWork = true;
CanCollaborate = true;
IsCompleted = false;

TotalWorkAmount = 10f;
}

public override bool IsInteractable(Creature creature, bool isDoInteract)
{
if (creature.CreatureType == Define.CreatureType.Alien)
return false;

if (!CanUseAgain && IsCompleted)
return false;

creature.IngameUI.InteractInfoUI.Show(InteractDescription.ToString());

if (CurrentWorkers.Count >= 3 || (!CanCollaborate && CurrentWorkers.Count >= 1))
return false;

if (!(creature.CreatureState == Define.CreatureState.Idle || creature.CreatureState == Define.CreatureState.Move))
return false;

if (((Crew)creature).Inventory.CurrentItem.ItemType != Define.ItemType.Battery)
return false;

if (isDoInteract)
Interact(creature);

return true;
}

public override void WorkComplete()
{
MyCrew.Inventory.CurrentItemIdx = -1;

base.WorkComplete();
}


public override void PlayInteractAnimation()
{
MyCrew.CrewAnimController.PlayKeypadUse();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Collections;
using UnityEngine;

public class Computer : BaseWorkStation
{
public Crew MyCrew => (Crew)MyWorker;
Expand All @@ -9,14 +6,14 @@ protected override void Init()
{
base.Init();

InteractDescription = "USE COMPUTER";

CanUseAgain = false;
CanRememberWork = true;
CanCollaborate = true;
IsCompleted = false;

TotalWorkAmount = 100f;
WorkingDescription = "Fixing Computer";
InteractDescription = "Fix computer";
}

public override void PlayInteractAnimation()
Expand Down
Loading

0 comments on commit 586a91b

Please sign in to comment.