Commit e33c955e authored by 18김민수's avatar 18김민수

Example event SD occurence update

parent 327cb047
...@@ -8,9 +8,27 @@ namespace ISEKAI_Model ...@@ -8,9 +8,27 @@ namespace ISEKAI_Model
{ {
Completed, Ready, Visible Completed, Ready, Visible
} }
public enum EventLocation
{
None,
BackMount,
Field,
WayToTown,
Farm, // Conditional
Mine, // Conditional
TaskLeaderHouse,
TechGuideStaffHouse,
TownSquare,
TownWell,
SecretaryHouse, // Conditional
TownWitchHouse // Conditional
}
public abstract class EventCore // Every future event must inherit this. public abstract class EventCore // Every future event must inherit this.
{ {
private bool _isActivatedAlready; public bool isNew => (_seasonMadeIn == game.turn.season) && (turnsLeft == givenMaxTurn);
public bool isActivatedAlready;
public List<(int, int)> choiceHistory = new List<(int, int)>(); // <item1>th choice, selected <item2>th branch. (0-based) public List<(int, int)> choiceHistory = new List<(int, int)>(); // <item1>th choice, selected <item2>th branch. (0-based)
public abstract int forcedEventPriority {get;} // 0 if the event is not forced event. public abstract int forcedEventPriority {get;} // 0 if the event is not forced event.
public abstract string eventName {get;} public abstract string eventName {get;}
...@@ -19,61 +37,38 @@ namespace ISEKAI_Model ...@@ -19,61 +37,38 @@ namespace ISEKAI_Model
public abstract int turnsLeft {get; protected set;} // how many turns left for this event to be gone. public abstract int turnsLeft {get; protected set;} // how many turns left for this event to be gone.
public abstract int cost {get;} // how many AP this event takes. public abstract int cost {get;} // how many AP this event takes.
public abstract Season availableSeason {get;} // when this event is available. public abstract Season availableSeason {get;} // when this event is available.
public abstract EventLocation location { get; }
public abstract List<Command> script { get; }
protected abstract bool exclusiveCondition(Game game); // exclusive emergence condition of each event. public Game game {get; private set;}
public static void InitEvents() // should add EVERY events when new event plan comes. private Season _seasonMadeIn = Season.None;
{ protected abstract bool exclusiveCondition(); // exclusive emergence condition of each event.
_activatedEvents.Add(new ExampleEvent1());
} public bool isRemovedLastTurn = false;
public static void OccurEvents(Game game) // Not recommended to call manually. Only called by Proceed().
public void ActivateEvent()
{ {
foreach (EventCore e in _activatedEvents) status = EventStatus.Visible;
{ turnsLeft = givenMaxTurn;
if (e.IsFirstVisible(game) && e.status == EventStatus.Ready && !e._isActivatedAlready) isActivatedAlready = true;
{
e.turnsLeft = e.givenMaxTurn;
e.status = EventStatus.Visible;
e._isActivatedAlready = true;
}
else if (e._isActivatedAlready)
{
if (e.seasonCheck(game) && e.turnsLeft > 0)
e.status = EventStatus.Visible;
else
e.status = EventStatus.Ready;
}
}
} }
protected EventCore()
protected EventCore(Game game)
{ {
status = EventStatus.Ready; status = EventStatus.Ready;
} this.game = game;
private static List<EventCore> _activatedEvents = new List<EventCore>(); // list of all activated events.
public static List<EventCore> GetAllEvents() // MOST IMPORTANT FUNCTION!
{
return _activatedEvents;
} }
public static void ReduceTurnsLeft() // Not recommended to call manually. Only called by Proceed().
{ public bool IsFirstVisible() // if this returns true, event is set to Visible.
foreach (EventCore e in _activatedEvents)
{
if(e._isActivatedAlready)
e.turnsLeft--;
if (e.turnsLeft <= 0 && e._isActivatedAlready)
{
e.status = EventStatus.Ready;
e._isActivatedAlready = false;
}
}
}
public bool IsFirstVisible(Game game) // if this returns true, event is set to Visible.
{ {
return exclusiveCondition(game) && seasonCheck(game); bool result;
result = exclusiveCondition() && seasonCheck();
if (result) _seasonMadeIn = game.turn.season;
return result && !isRemovedLastTurn;
} }
public bool seasonCheck(Game game) public bool seasonCheck()
{ {
bool seasonCheck; bool seasonCheck;
if (availableSeason == Season.None) if (availableSeason == Season.None)
...@@ -82,6 +77,16 @@ namespace ISEKAI_Model ...@@ -82,6 +77,16 @@ namespace ISEKAI_Model
seasonCheck = availableSeason == game.turn.season; seasonCheck = availableSeason == game.turn.season;
return seasonCheck; return seasonCheck;
} }
public abstract List<Command> script {get;}
public void CompleteEvent(Game game) // should be called when the event is completed.
{
game.remainAP -= cost;
status = EventStatus.Completed;
}
public void ReduceTurnsLeft()
{
turnsLeft--;
}
} }
} }
using System; using System;
using System.Collections.Generic;
using System.Linq;
namespace ISEKAI_Model namespace ISEKAI_Model
{ {
...@@ -8,15 +10,17 @@ namespace ISEKAI_Model ...@@ -8,15 +10,17 @@ namespace ISEKAI_Model
{ {
turn = new Turn(); turn = new Turn();
town = new Town(); town = new Town();
EventCore.InitEvents(); _InitEvents();
Proceed(); Proceed();
} }
public const int maxAP = 4; // max AP of the game. public const int maxAP = 4; // max AP of the game.
public int remainAP {get; private set;} // remaining AP of the game. public int remainAP {get; set;} // remaining AP of the game.
public Town town {get; private set;} // main town of the game. see Town class. public Town town {get; private set;} // main town of the game. see Town class.
public Turn turn {get; private set;} // indicating season, turn number, etc. see Turn class. public Turn turn {get; private set;} // indicating season, turn number, etc. see Turn class.
public List<EventCore> allEventsList = new List<EventCore>();
public List<EventCore> visibleEventsList => allEventsList.FindAll(e => e.status == EventStatus.Visible);
public void Proceed() // if you want to move on (next season, or next turn), just call it. public void Proceed() // if you want to move on (next season, or next turn), just call it.
{ {
...@@ -25,20 +29,13 @@ namespace ISEKAI_Model ...@@ -25,20 +29,13 @@ namespace ISEKAI_Model
case State.PreTurn: case State.PreTurn:
_DoPreTurnBehavior(); _DoPreTurnBehavior();
turn.MoveToNextState(); turn.MoveToNextState();
if (town.totalPleasantAmount <= 0)
{
// TODO: Make bad ending event and set it to Visible.
}
else
{
}
break; break;
case State.InTurn: case State.InTurn:
if (turn.IsFormerSeason()) if (turn.IsFormerSeason())
{ {
turn.MoveToNextSeason(); turn.MoveToNextSeason();
EventCore.OccurEvents(this); _OccurEvents();
} }
else else
{ {
...@@ -49,10 +46,6 @@ namespace ISEKAI_Model ...@@ -49,10 +46,6 @@ namespace ISEKAI_Model
case State.PostTurn: case State.PostTurn:
_DoPostTurnBehavior(); _DoPostTurnBehavior();
turn.MoveToNextState();
turn.MoveToNextSeason();
turn.IncreaseTurnNumber();
EventCore.ReduceTurnsLeft();
Proceed(); Proceed();
break; break;
} }
...@@ -64,13 +57,18 @@ namespace ISEKAI_Model ...@@ -64,13 +57,18 @@ namespace ISEKAI_Model
remainAP = maxAP; remainAP = maxAP;
town.AddFoodProduction(); town.AddFoodProduction();
town.ApplyPleasantChange(); town.ApplyPleasantChange();
EventCore.OccurEvents(this); _SetAllEventActivable();
_OccurEvents();
} }
private void _DoPostTurnBehavior() private void _DoPostTurnBehavior()
{ {
//Console.WriteLine ("This is PostTurn"); //Console.WriteLine ("This is PostTurn");
town.ConsumeFood(); town.ConsumeFood();
town.ApplyPleasantChange(); town.ApplyPleasantChange();
turn.MoveToNextState();
turn.MoveToNextSeason();
turn.IncreaseTurnNumber();
_ReduceEveryEventsTurnsLeft();
} }
public void ApplyChoiceEffect(ChoiceEffect choiceEffect) public void ApplyChoiceEffect(ChoiceEffect choiceEffect)
...@@ -128,5 +126,52 @@ namespace ISEKAI_Model ...@@ -128,5 +126,52 @@ namespace ISEKAI_Model
throw new InvalidOperationException("Error on ApplyChoiceEffect()"); throw new InvalidOperationException("Error on ApplyChoiceEffect()");
} }
} }
private void _ReduceEveryEventsTurnsLeft() // Not recommended to call manually. Only called by Proceed().
{
foreach (EventCore e in allEventsList)
{
if(e.isActivatedAlready)
e.ReduceTurnsLeft();
if (e.turnsLeft <= 0 && e.isActivatedAlready)
{
e.status = EventStatus.Ready;
e.isActivatedAlready = false;
e.isRemovedLastTurn = true;
}
}
}
private void _SetAllEventActivable()
{
foreach (EventCore e in allEventsList)
e.isRemovedLastTurn = false;
}
private void _OccurEvents() // Not recommended to call manually. Only called by Proceed().
{
foreach (EventCore e in allEventsList)
{
if (e.IsFirstVisible() &&
e.status == EventStatus.Ready &&
!e.isActivatedAlready)
{
e.ActivateEvent();
}
else if (e.isActivatedAlready)
{
if (e.seasonCheck() && e.turnsLeft > 0)
e.status = EventStatus.Visible;
else
e.status = EventStatus.Ready;
}
}
}
private void _InitEvents() // should add EVERY events when new event plan comes.
{
allEventsList.Add(new ExampleEvent1(this));
}
} }
} }
\ No newline at end of file
...@@ -5,15 +5,15 @@ namespace ISEKAI_Model ...@@ -5,15 +5,15 @@ namespace ISEKAI_Model
{ {
class ExampleEvent1 : EventCore class ExampleEvent1 : EventCore
{ {
public override string eventName {get {return " ̺Ʈ";}} public override string eventName {get {return "예시 이벤트";}}
public override int givenMaxTurn {get {return 4;}} public override int givenMaxTurn {get {return 4;}}
public override int turnsLeft {get; protected set;} public override int turnsLeft {get; protected set;}
public override int cost {get {return 2;}} public override int cost {get {return 2;}}
public override Season availableSeason {get {return Season.Summer;}} public override Season availableSeason {get {return Season.Summer;}}
public override int forcedEventPriority {get {return 0;}} public override int forcedEventPriority {get {return 0;}}
public override EventLocation location { get { return EventLocation.Field; } }
public override List<Command> script {get {return Parser.ParseScript("Scripts/ExampleEvent1.txt");}} // command list. public override List<Command> script {get {return Parser.ParseScript("Scripts/ExampleEvent1.txt");}} // command list.
protected override bool exclusiveCondition(Game game) protected override bool exclusiveCondition()
{ {
bool chanceCheck; bool chanceCheck;
Random r = new Random(); Random r = new Random();
...@@ -23,13 +23,13 @@ namespace ISEKAI_Model ...@@ -23,13 +23,13 @@ namespace ISEKAI_Model
else else
chanceCheck = false; chanceCheck = false;
bool foodCheck; bool foodCheck;
if (game.town.remainFoodAmount >= 100) if (game.town.totalPleasantAmount >= 100)
foodCheck = true; foodCheck = true;
else else
foodCheck = false; foodCheck = false;
return chanceCheck && foodCheck; return chanceCheck && foodCheck;
} }
public ExampleEvent1() public ExampleEvent1(Game game) : base(game)
{ {
turnsLeft = 0; turnsLeft = 0;
} }
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ISEKAI_Model;
public class EventLoader : MonoBehaviour // This script is attatched to event SD for them to load EventScene when clicked.
{
void OnMouseDown()
{
Debug.Log("asdf");
}
}
...@@ -2,9 +2,19 @@ ...@@ -2,9 +2,19 @@
using UnityEngine; using UnityEngine;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine.UI;
public class EventManager : MonoBehaviour public class EventManager : MonoBehaviour
{ {
public GameObject containerFullScript;
public GameObject containerChoice;
public GameObject containerConversation;
public Text textCharacterInfo;
public Text textScript;
public Text textFullScript;
public EventManager(EventCore eventCore) // when playing new event, this instance should be made. public EventManager(EventCore eventCore) // when playing new event, this instance should be made.
{ {
...@@ -91,11 +101,18 @@ public class EventManager : MonoBehaviour ...@@ -91,11 +101,18 @@ public class EventManager : MonoBehaviour
private void _Explanation(Explanation explanation) private void _Explanation(Explanation explanation)
{ {
containerChoice.SetActive(false);
containerConversation.SetActive(false);
containerFullScript.SetActive(true);
} }
private void _Conversation(Conversation conversation) private void _Conversation(Conversation conversation)
{ {
containerChoice.SetActive(false);
containerConversation.SetActive(true);
containerFullScript.SetActive(false);
textCharacterInfo.text = conversation.characterName;
} }
...@@ -166,7 +183,9 @@ public class EventManager : MonoBehaviour ...@@ -166,7 +183,9 @@ public class EventManager : MonoBehaviour
private void _Choice(Choice choice) private void _Choice(Choice choice)
{ {
containerChoice.SetActive(true);
containerConversation.SetActive(false);
containerFullScript.SetActive(false);
} }
private void _VFXTransition(VFXTransition vfxTransition) private void _VFXTransition(VFXTransition vfxTransition)
......
...@@ -3,10 +3,12 @@ using System.Collections.Generic; ...@@ -3,10 +3,12 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using ISEKAI_Model; using ISEKAI_Model;
using System.Linq;
public class GameManager : MonoBehaviour public class GameManager : MonoBehaviour
{ {
public static GameManager instance; public static GameManager instance;
public EventManager currentEvent;
void Awake() void Awake()
{ {
...@@ -22,23 +24,8 @@ public class GameManager : MonoBehaviour ...@@ -22,23 +24,8 @@ public class GameManager : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
textFood.text = game.town.remainFoodAmount.ToString();
textPleasant.text = game.town.totalPleasantAmount + "/" + 200;
textTurn.text = game.turn.ToString();
}
public Text textPleasant; }
public Text textFood;
public Text textTurn;
public Game game = new Game(); // represents one game. public Game game = new Game(); // represents one game.
public void OnClickNextTurn()
{
game.Proceed();
textFood.text = game.town.remainFoodAmount.ToString();
textPleasant.text = game.town.totalPleasantAmount + "/" + 200;
textTurn.text = game.turn.ToString();
}
} }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ISEKAI_Model;
using UnityEngine.UI;
public class UIEventManager : MonoBehaviour
{
public Button buttonSkip;
public Button buttonAuto;
public Button buttonNext;
private EventManager _eventManager;
// Start is called before the first frame update
void Start()
{
_eventManager = GameManager.instance.currentEvent;
}
// Update is called once per frame
void Update()
{
}
public void OnClickSkipButton()
{
}
public void OnClickAutoButton()
{
}
public void OnClickNextButton()
{
_eventManager.ExecuteOneScript();
}
}
...@@ -3,6 +3,7 @@ using System.Collections.Generic; ...@@ -3,6 +3,7 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using System; using System;
using UnityEngine.UI; using UnityEngine.UI;
using ISEKAI_Model;
public class UITownManager : MonoBehaviour public class UITownManager : MonoBehaviour
{ {
...@@ -11,31 +12,36 @@ public class UITownManager : MonoBehaviour ...@@ -11,31 +12,36 @@ public class UITownManager : MonoBehaviour
Outskirts, Town Outskirts, Town
} }
public GameObject btnLocation; public Transform eventPrefab;
public GameObject moveBtnLocation;
public GameObject background; public GameObject background;
private Button _btnLocation; public Text textPleasant;
private Text _txtlocation; public Text textFood;
public Text textTurn;
private Button _moveBtnLocation;
private Text _moveTxtlocation;
private SpriteRenderer _background; private SpriteRenderer _background;
private Location _location; private Location _location;
private GameObject _eventList;
public Sprite[] turnsLeftSprites;
public Sprite[] seasonSprites;
public Sprite[] numberSprites;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
_location = Location.Outskirts; _location = Location.Outskirts;
_background = background.GetComponent<SpriteRenderer>(); _background = background.GetComponent<SpriteRenderer>();
_btnLocation = btnLocation.GetComponent<Button>(); _moveBtnLocation = moveBtnLocation.GetComponent<Button>();
_txtlocation = btnLocation.GetComponentInChildren<Text>(); _moveTxtlocation = moveBtnLocation.GetComponentInChildren<Text>();
_moveBtnLocation.onClick.AddListener(OnMoveBtnClick);
_btnLocation.onClick.AddListener(OnMoveBtnClick);
}
// Update is called once per frame
void Update()
{
} }
//If button clicked, change location, and replace ui depend on location
public void OnMoveBtnClick() public void OnMoveBtnClick()
{ {
switch (_location) switch (_location)
...@@ -43,17 +49,91 @@ public class UITownManager : MonoBehaviour ...@@ -43,17 +49,91 @@ public class UITownManager : MonoBehaviour
case Location.Outskirts: case Location.Outskirts:
_background.sprite = Resources.Load<Sprite>("bg_town"); _background.sprite = Resources.Load<Sprite>("bg_town");
_location = Location.Town; _location = Location.Town;
_txtlocation.text = "마을 외곽으로"; _moveTxtlocation.text = "마을 외곽으로";
break; break;
case Location.Town: case Location.Town:
_background.sprite = Resources.Load<Sprite>("bg_outskirts"); _background.sprite = Resources.Load<Sprite>("bg_outskirts");
_location = Location.Outskirts; _location = Location.Outskirts;
_txtlocation.text = "마을로"; _moveTxtlocation.text = "마을로";
break; break;
default: default:
throw new InvalidOperationException("Location should be town or outskirts"); throw new InvalidOperationException("Location should be town or outskirts");
} }
} }
public void OnClickNextTurnButton()
{
Game _game = GameManager.instance.game;
_game.Proceed();
textFood.text = _game.town.remainFoodAmount.ToString();
textPleasant.text = _game.town.totalPleasantAmount + "/" + 200;
textTurn.text = _game.turn.ToString();
TryInstantiateEventSDs();
TryUpdateEventSDs();
}
public List<Transform> eventSDList = new List<Transform>();
public void TryInstantiateEventSDs() // find an events which is newly set to visible and make an SD of them.
{
Game game = GameManager.instance.game;
foreach (EventCore e in game.visibleEventsList)
{
if (e.forcedEventPriority > 0) continue; // if event is forced event, there is no need to make SD.
if (e.isNew) // if
{
var sd = Instantiate(eventPrefab, new Vector3(0, 0, 0), Quaternion.identity);
//TODO : set event sprite to the sprite of this event.
sd.name = e.eventName;
sd.GetChild(2).GetComponent<SpriteRenderer>().sprite = turnsLeftSprites[e.givenMaxTurn - 1]; // sprite array index is 0-based, but starts with sprite of 1, so -1 is needed.
sd.GetChild(1).GetChild(0).GetComponent<SpriteRenderer>().sprite = numberSprites[e.cost];
if (e.availableSeason == Season.None)
sd.GetChild(4).gameObject.SetActive(false);
else
sd.GetChild(4).GetComponent<SpriteRenderer>().sprite = seasonSprites[(int)e.availableSeason - 1];
eventSDList.Add(sd);
}
}
}
public void TryUpdateEventSDs()
{
Game game = GameManager.instance.game;
List<Transform> toDestroyList = new List<Transform>();
foreach(Transform sd in eventSDList)
{
EventCore e = GetEventCoreFromEventSd(sd);
if (e.turnsLeft <= 0)
{
toDestroyList.Add(sd);
continue;
}
if (e.seasonCheck())
sd.gameObject.SetActive(true);
else
sd.gameObject.SetActive(false);
sd.GetChild(2).GetComponent<SpriteRenderer>().sprite = turnsLeftSprites[e.turnsLeft - 1]; // sprite array index is 0-based, but starts with sprite of 1, so -1 is needed.
sd.GetChild(1).GetChild(0).GetComponent<SpriteRenderer>().sprite = numberSprites[e.cost];
if (e.availableSeason == Season.None)
sd.GetChild(4).gameObject.SetActive(false);
else
sd.GetChild(4).GetComponent<SpriteRenderer>().sprite = seasonSprites[(int)e.availableSeason - 1];
if (e.turnsLeft != e.givenMaxTurn)
sd.GetChild(3).gameObject.SetActive(false);
}
foreach(Transform sd in toDestroyList)
{
Destroy(sd.gameObject);
eventSDList.Remove(sd);
}
}
public EventCore GetEventCoreFromEventSd(Transform sd)
{
Game game = GameManager.instance.game;
return game.allEventsList.Find(e => e.eventName.Equals(sd.name));
}
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
--- !u!78 &1 --- !u!78 &1
TagManager: TagManager:
serializedVersion: 2 serializedVersion: 2
tags: [] tags:
- Event
layers: layers:
- Default - Default
- TransparentFX - TransparentFX
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment