-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattleReporter.cs
126 lines (108 loc) · 4.39 KB
/
BattleReporter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Monomon.Battle;
using Monomon.Input;
using Monomon.State;
using Monomon.ViewModels;
using Monomon.Views.Scenes;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Monomon
{
public enum Sounds
{
Attack_Tackle,
TakeDamage,
XpUP,
}
public class BattleReporter
{
private readonly SpriteBatch batch;
private readonly StateStack<double> _stack;
private Action<Sounds> _soundCallback;
private Texture2D _sprites;
private SpriteFont _font;
private IINputHandler _input;
private GraphicsDevice _gd;
public List<string> Messages { get; set; }
public BattleReporter(SpriteBatch batch, GraphicsDevice gd, State.StateStack<double> stack, IINputHandler input, SpriteFont font, Texture2D sprites, Action<Sounds> soundCallback)
{
_soundCallback = soundCallback;
_sprites = sprites;
_font = font;
_input = input;
_gd = gd;
if (batch is null)
{
throw new ArgumentNullException(nameof(batch));
}
this.batch = batch;
_stack = stack;
Messages = new List<string>();
}
TimedState TimedMessage(string message)
{
return new TimedState(new MessageScene(_gd, message, _font, _sprites), 2500, _input);
}
ConfirmState ConfirmMessage(string message)
{
return new ConfirmState(new MessageScene(_gd, message, _font, _sprites, true), _input);
}
public void OnAttack(BattleMessage message, Mons.Mobmon attacker, Mons.Mobmon _oponent, Action continueWith, BattleCardViewModel attackerCard, BattleCardViewModel oponentCard)
{
var attackInfoState = TimedMessage($"{message.attacker} used {message.name}");
_stack.BeginStateSequence();
_stack.AddState(attackInfoState);
var ey = oponentCard.PortraitOffsetY;
var hitAnim = new TweenState((arg) =>
{
oponentCard.PortraitOffsetY = (int)(ey + Math.Sin(3.14 * arg.lerp) * 20);
}, () =>
{
}, 0, 1, .3f);
var y = attackerCard.PortraitOffsetY;
var attackAnimation = new TweenState((arg) =>
{
attackerCard.PortraitOffsetY = (int)(y + Math.Sin(3.14 * arg.lerp) * -40);
}, () =>
{
_soundCallback(Sounds.Attack_Tackle);
}, 0, 1, .3f);
_stack.AddState(attackAnimation);
_stack.AddState(hitAnim, () => { });
var health = _oponent.Health;
var hasFainted = false;
var healthbarUpdateState = new TweenState((arg) => _oponent.Health = (float)(health - arg.lerp), () =>
{
_oponent.Health = health - message.damage;
hasFainted = _oponent.Health <= 0;
}, 0.0f, Math.Min(message.damage, health), 1.0f, EasingFunc.EaseOutCube);
_stack.AddState(healthbarUpdateState, () =>
{
_oponent.Health = health - message.damage;
});
if (health - message.damage <= 0)
{
var offset = 0;
var dropPoirtrait = new TweenState((arg) => { oponentCard.PoirtrateAnimDelta = ((int)(offset + arg.lerp)); oponentCard.Dying = true; }, () =>
{
}, 0.0f, oponentCard.PortraitSrc.Height, 0.5f, EasingFunc.EaseInBack);
_stack.AddState(dropPoirtrait, null, () => _soundCallback(Sounds.TakeDamage));
_stack.AddState(ConfirmMessage($"{_oponent.Name} has fainted"));
_stack.AddState(ConfirmMessage("XP Gained"));
var xp = attacker.Xp;
var xpUpdate = new TweenState((arg) => attacker.Xp = (float)(xp + arg.lerp), () =>
{
attacker.Xp = xp + 20;
}, 0.0f, 20, 1.0f, EasingFunc.EaseOutCube);
_stack.AddState(xpUpdate, null, () => _soundCallback(Sounds.XpUP));
}
_stack.EndStateSecence(() =>
{
if (!hasFainted) //continue will swap to next round, if we dont we will prompt for which turn to go next
continueWith();
});
}
}
}