Commit 327cb047 authored by 18김민수's avatar 18김민수

Event minor update.

parent 66671a5c
using System;
using System.Collections.Generic;
using System.Linq;
namespace ISEKAI_Model
{
public enum EventStatus
{
Completed, Ready, Visible
}
public abstract class EventCore // Every future event must inherit this.
{
private bool _isActivatedAlready;
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 string eventName {get;}
public EventStatus status {get; set;}
public abstract int givenMaxTurn {get;}
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 Season availableSeason {get;} // when this event is available.
protected abstract bool exclusiveCondition(Game game); // exclusive emergence condition of each event.
public static void InitEvents() // should add EVERY events when new event plan comes.
{
_activatedEvents.Add(new ExampleEvent1());
}
public static void OccurEvents(Game game) // Not recommended to call manually. Only called by Proceed().
{
foreach (EventCore e in _activatedEvents)
{
if (e.IsFirstVisible(game) && e.status == EventStatus.Ready && !e._isActivatedAlready)
{
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()
{
status = EventStatus.Ready;
}
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().
{
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);
}
public bool seasonCheck(Game game)
{
bool seasonCheck;
if (availableSeason == Season.None)
seasonCheck = true;
else
seasonCheck = availableSeason == game.turn.season;
return seasonCheck;
}
public abstract List<Command> script {get;}
}
}
......@@ -8,7 +8,7 @@ namespace ISEKAI_Model
{
turn = new Turn();
town = new Town();
Event.InitEvents();
EventCore.InitEvents();
Proceed();
}
public const int maxAP = 4; // max AP of the game.
......@@ -38,7 +38,7 @@ namespace ISEKAI_Model
if (turn.IsFormerSeason())
{
turn.MoveToNextSeason();
Event.OccurEvents(this);
EventCore.OccurEvents(this);
}
else
{
......@@ -52,7 +52,7 @@ namespace ISEKAI_Model
turn.MoveToNextState();
turn.MoveToNextSeason();
turn.IncreaseTurnNumber();
Event.ReduceTurnsLeft();
EventCore.ReduceTurnsLeft();
Proceed();
break;
}
......@@ -64,7 +64,7 @@ namespace ISEKAI_Model
remainAP = maxAP;
town.AddFoodProduction();
town.ApplyPleasantChange();
Event.OccurEvents(this);
EventCore.OccurEvents(this);
}
private void _DoPostTurnBehavior()
{
......
......@@ -4,7 +4,7 @@ namespace ISEKAI_Model
{
public interface IMinigamePlayable
{
int playerScore {get; set;}
void DoMinigameBehavior(int score);
int playerScore {get; set;} // result of playing minigame.
void DoMinigameBehavior(int score); // do something with result score.
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
namespace ISEKAI_Model
{
class ExampleEvent1 : EventCore
{
public override string eventName {get {return " ̺Ʈ";}}
public override int givenMaxTurn {get {return 4;}}
public override int turnsLeft {get; protected set;}
public override int cost {get {return 2;}}
public override Season availableSeason {get {return Season.Summer;}}
public override int forcedEventPriority {get {return 0;}}
public override List<Command> script {get {return Parser.ParseScript("Scripts/ExampleEvent1.txt");}} // command list.
protected override bool exclusiveCondition(Game game)
{
bool chanceCheck;
Random r = new Random();
int cond = r.Next(0, 10);
if (cond >= 0 && cond < 3)
chanceCheck = true;
else
chanceCheck = false;
bool foodCheck;
if (game.town.remainFoodAmount >= 100)
foodCheck = true;
else
foodCheck = false;
return chanceCheck && foodCheck;
}
public ExampleEvent1()
{
turnsLeft = 0;
}
}
}
\ No newline at end of file
......@@ -24,7 +24,9 @@ namespace ISEKAI_Model
@"^(\d?)\-?\-?(\d?) ?Load Minigame ""(.*)""$", //13
@"^(\d?)\-?\-?(\d?) ?Load Video ""(.*)""$", //14
@"^(\d?)\-?\-?(\d?) ?Choice$", //15
@"-- ""(.*)""( \-(\w+) \(([\+\-\*])(\d+)\))*"};
@"-- ""(.*)""( \-(\w+) \(([\+\-\*])(\d+)\))*", // 16
@"^(\d?)\-?\-?(\d?) ?VFXTransition$", //17
@"^(\d?)\-?\-?(\d?) ?VFXPause \-(.*)$"}; //18
private static SpriteLocation _ParseSpriteLocation(string location)
{
if(location.Equals("left"))
......@@ -75,11 +77,11 @@ namespace ISEKAI_Model
else
{
int cNumber;
int cResult = Int32.Parse(choiceResult);
int cResult = int.Parse(choiceResult);
if (choiceNumber == "")
cNumber = 0;
else
cNumber = Int32.Parse(choiceNumber);
cNumber = int.Parse(choiceNumber);
command.choiceDependency = (cNumber,cResult);
}
}
......@@ -170,7 +172,7 @@ namespace ISEKAI_Model
string filePath = match.Groups[3].Value;
string width = match.Groups[4].Value;
string height = match.Groups[5].Value;
var vfxLoadSprite = new VFXLoadSprite(filePath, Int32.Parse(width), Int32.Parse(height));
var vfxLoadSprite = new VFXLoadSprite(filePath, int.Parse(width), int.Parse(height));
_SetChoiceDependency(vfxLoadSprite, match.Groups[1].Value, match.Groups[2].Value);
refinedList.Add(vfxLoadSprite);
}
......@@ -224,6 +226,19 @@ namespace ISEKAI_Model
refinedList.Add(choice);
choiceNumber++;
}
else if ((match = Regex.Match(command, _commandPattern[17])).Success)
{
var vfxTransition = new VFXTransition();
_SetChoiceDependency(vfxTransition, match.Groups[1].Value, match.Groups[2].Value);
refinedList.Add(vfxTransition);
}
else if ((match = Regex.Match(command, _commandPattern[18])).Success)
{
string second = match.Groups[3].Value;
var vfxPause = new VFXPause(int.Parse(second));
_SetChoiceDependency(vfxPause, match.Groups[1].Value, match.Groups[2].Value);
refinedList.Add(vfxPause);
}
}
return refinedList;
}
......
using System;
namespace ISEKAI_Model
{
class VFXPause : Command
{
public override int commandNumber { get { return 18; } }
public int second { get; private set; }
public VFXPause(int second)
{
this.second = second;
}
}
}
using System;
namespace ISEKAI_Model
{
class VFXTransition : Command
{
public override int commandNumber { get { return 17; } }
}
}
using ISEKAI_Model;
using UnityEngine;
using System;
using System.Collections.Generic;
public class EventManager : MonoBehaviour
{
public EventManager(EventCore eventCore) // when playing new event, this instance should be made.
{
currentEvent = eventCore;
scriptEnumerator = eventCore.script.GetEnumerator();
}
public EventCore currentEvent { get; private set; } // when event SD is clicked and scene changed, it should be set to that event.
public List<Command>.Enumerator scriptEnumerator;
public void ExecuteOneScript()
{
// TODO:
// when MoveNext() returns false, it must go back to TownScene.
scriptEnumerator.MoveNext();
_ExecuteCommand(scriptEnumerator.Current);
}
private void _ExecuteCommand(Command c)
{
switch (c.commandNumber)
{
case 0:
_Explanation(c as Explanation);
break;
case 1:
_Conversation(c as Conversation);
break;
case 2:
_LoadCharacter(c as LoadCharacter);
break;
case 3:
_UnloadCharacter(c as UnloadCharacter);
break;
case 4:
_LoadBackground(c as LoadBackground);
break;
case 5:
_PlayMusic(c as PlayMusic);
break;
case 6:
_StopMusic(c as StopMusic);
break;
case 7:
_LoadCG(c as LoadCG);
break;
case 8:
_UnloadCG(c as UnloadCG);
break;
case 9:
_VFXCamerashake(c as VFXCameraShake);
break;
case 10:
_VFXLoadSprite(c as VFXLoadSprite);
break;
case 11:
_VFXUnloadSprite(c as VFXUnloadSprite);
break;
case 12:
_VFXSound(c as VFXSound);
break;
case 13:
_LoadMinigame(c as LoadMinigame);
break;
case 14:
_LoadVideo(c as LoadVideo);
break;
case 15:
_Choice(c as Choice);
break;
case 16:
break;
case 17:
_VFXTransition(c as VFXTransition);
break;
case 18:
_VFXPause(c as VFXPause);
break;
default:
throw new NotImplementedException("The command which holds that number is not implemented.");
}
}
private void _Explanation(Explanation explanation)
{
}
private void _Conversation(Conversation conversation)
{
}
private void _LoadCharacter(LoadCharacter loadCharacter)
{
}
private void _UnloadCharacter(UnloadCharacter unloadCharacter)
{
}
private void _LoadBackground(LoadBackground loadBackground)
{
}
private void _PlayMusic(PlayMusic playMusic)
{
}
private void _StopMusic(StopMusic stopMusic)
{
}
private void _LoadCG(LoadCG loadCG)
{
}
private void _UnloadCG(UnloadCG unloadCG)
{
}
private void _VFXCamerashake(VFXCameraShake vfxCameraShake)
{
}
private void _VFXLoadSprite(VFXLoadSprite vfxLoadSprite)
{
}
private void _VFXUnloadSprite(VFXUnloadSprite vfxUnloadSprite)
{
}
private void _VFXSound(VFXSound vfxSound)
{
}
private void _LoadMinigame(LoadMinigame loadMinigame)
{
}
private void _LoadVideo(LoadVideo loadVideo)
{
}
private void _Choice(Choice choice)
{
}
private void _VFXTransition(VFXTransition vfxTransition)
{
}
private void _VFXPause(VFXPause vfxPause)
{
}
}
......@@ -6,6 +6,19 @@ using ISEKAI_Model;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else
Destroy(gameObject);
}
// Start is called before the first frame update
void Start()
{
......@@ -14,11 +27,6 @@ public class GameManager : MonoBehaviour
textTurn.text = game.turn.ToString();
}
// Update is called once per frame
void Update()
{
}
public Text textPleasant;
public Text textFood;
public Text textTurn;
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIConversationManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
public class UITownManager : MonoBehaviour
{
private enum Location
{
Outskirts, Town
}
public GameObject btnLocation;
public GameObject background;
private Button _btnLocation;
private Text _txtlocation;
private SpriteRenderer _background;
private Location _location;
// Start is called before the first frame update
void Start()
{
_location = Location.Outskirts;
_background = background.GetComponent<SpriteRenderer>();
_btnLocation = btnLocation.GetComponent<Button>();
_txtlocation = btnLocation.GetComponentInChildren<Text>();
_btnLocation.onClick.AddListener(OnMoveBtnClick);
}
// Update is called once per frame
void Update()
{
}
public void OnMoveBtnClick()
{
switch (_location)
{
case Location.Outskirts:
_background.sprite = Resources.Load<Sprite>("bg_town");
_location = Location.Town;
_txtlocation.text = "마을 외곽으로";
break;
case Location.Town:
_background.sprite = Resources.Load<Sprite>("bg_outskirts");
_location = Location.Outskirts;
_txtlocation.text = "마을로";
break;
default:
throw new InvalidOperationException("Location should be town or outskirts");
}
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -47,3 +47,6 @@ TagManager:
- name: people
uniqueID: 2371533901
locked: 0
- name: text
uniqueID: 4289377047
locked: 0
......@@ -12,7 +12,7 @@ UnityConnectSettings:
m_TestInitMode: 0
CrashReportingSettings:
m_EventUrl: https://perf-events.cloud.unity3d.com
m_Enabled: 0
m_Enabled: 1
m_LogBufferSize: 10
m_CaptureEditorExceptions: 1
UnityPurchasingSettings:
......
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