Compare commits

...

2 Commits

Author SHA1 Message Date
e54ba4652f fixed issue with display / initializing unit with base class 2026-09-28 23:11:05 -05:00
cfd615bf07 more cleanup and refactoring 2026-09-27 12:35:08 -05:00
26 changed files with 292 additions and 757 deletions

View File

@ -6,7 +6,7 @@ using System.Reflection.Metadata;
using System.Text; using System.Text;
using Johnmagotchi.Core.tools; using Johnmagotchi.Core.tools;
using Johnmagotchi.Data; using Johnmagotchi.Data;
using Johnmagotchi.GameContent.Objects.Units.BattleObjects; using Johnmagotchi.GameContent.Objects.BattleObjects;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;

View File

@ -1,4 +1,4 @@
using Johnmagotchi.GameContent.Objects.Units.BattleObjects; using Johnmagotchi.GameContent.Objects.BattleObjects;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@ -1,6 +1,4 @@
using Johnmagotchi.GameContent.Objects.Units; using Johnmagotchi.GameContent.Objects.Units;
using Johnmagotchi.GameContent.Objects.Units.BattleObjects;
using Johnmagotchi.GameContent.Units;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -16,7 +14,8 @@ namespace Johnmagotchi.GameContent.Logic
{ {
private static double CriticalMultiplier = 1.5; private static double CriticalMultiplier = 1.5;
public static Random Random = new Random(); public static Random Random = new Random();
public static BattleResults RunBattle(ref Unit Attacker, ref Unit Defender, AttackObj attack, AttackObj counterAttack) { public static BattleResults RunBattle(ref Unit Attacker, ref Unit Defender)
{
// these are debugs, should be parsed from attack + unit combos // these are debugs, should be parsed from attack + unit combos
bool IsCounterAttackOccuring = true; bool IsCounterAttackOccuring = true;
@ -25,98 +24,99 @@ namespace Johnmagotchi.GameContent.Logic
BattleResults results = new BattleResults(); // battle results will determine how the battles are animated BattleResults results = new BattleResults(); // battle results will determine how the battles are animated
// for each combat, we need to do each attack phase that occurs apply results here //// for each combat, we need to do each attack phase that occurs apply results here
//Initial Attack ////Initial Attack
HandleAttackPhase(ref Attacker, ref Defender, attack, ref results, false); //HandleAttackPhase(ref Attacker, ref Defender, attack, ref results, false);
//Enemy's counter attack ////Enemy's counter attack
if (IsCounterAttackOccuring) //if (IsCounterAttackOccuring)
{ //{
HandleAttackPhase(ref Defender, ref Attacker, counterAttack, ref results, true); // HandleAttackPhase(ref Defender, ref Attacker, counterAttack, ref results, true);
} //}
// FE style double attack //// FE style double attack
if (IsDoubleAttackOccuring) //if (IsDoubleAttackOccuring)
{ //{
HandleAttackPhase(ref Attacker, ref Defender, attack, ref results, false); // HandleAttackPhase(ref Attacker, ref Defender, attack, ref results, false);
} //}
// FE style Double Counter Attack //// FE style Double Counter Attack
if (IsDoubleCounterAttackOccuring) //if (IsDoubleCounterAttackOccuring)
{ //{
HandleAttackPhase(ref Defender, ref Attacker, counterAttack, ref results, true); // HandleAttackPhase(ref Defender, ref Attacker, counterAttack, ref results, true);
} //}
return results; return results;
} }
// this is each step // this is each step
public static void HandleAttackPhase( //public static void HandleAttackPhase(
ref Unit Attacker, ref Unit Defender, AttackObj attack, // ref Unit Attacker, ref Unit Defender, AttackObj attack,
ref BattleResults results, bool isCounter) // ref BattleResults results, bool isCounter)
{ //{
int hitcount = attack.BaseHitCount; // anything that adjusts how many times an attack happens PER PHASE should be adjusted here // int hitcount = attack.BaseHitCount; // anything that adjusts how many times an attack happens PER PHASE should be adjusted here
for (int i = 0; i < hitcount; i++) { // for (int i = 0; i < hitcount; i++) {
int hitRoll = BattleLogic.Random.Next(100) + 1; // random int 1 - 100
int hitThreshold = attack.BaseAccuracy + Attacker.stats.baseStats.Speed - Defender.stats.baseStats.Speed;
// this should be adjusted, in FE games its usally something like...... // int hitRoll = BattleLogic.Random.Next(100) + 1; // random int 1 - 100
// ATTACKER = Hit + (Skill × 2) + (Luck / 2) + (Support bonus)+(Weapon triangle advantage/ disadvantage) +(S level bonus) // int hitThreshold = attack.BaseAccuracy + Attacker.stats.baseStats.Speed - Defender.stats.baseStats.Speed;
// DEFENDER = ((Attack speed × 2) +(Luck) + (Terrain bonus) +(Support bonus) +Tactician bonus) )
// hit perentage = attacker - defender
int critThreshold = 95; // // this should be adjusted, in FE games its usally something like......
// // ATTACKER = Hit + (Skill × 2) + (Luck / 2) + (Support bonus)+(Weapon triangle advantage/ disadvantage) +(S level bonus)
// // DEFENDER = ((Attack speed × 2) +(Luck) + (Terrain bonus) +(Support bonus) +Tactician bonus) )
// // hit perentage = attacker - defender
// int critThreshold = 95;
if (hitRoll < hitThreshold) //handle misses // if (hitRoll < hitThreshold) //handle misses
{ // {
results.addResult(BattleResults.resultType.MISS, 0, isCounter);
}
else if (hitRoll >= critThreshold) //Handle Crits
{
if (Defender.stats.status.CurrentShieldCount > 1) Defender.stats.status.CurrentShieldCount--; // as is, crits ignore shields but should still tick a shield down
if (Defender.stats.status.CurrentShieldCount < 0) Defender.stats.status.CurrentShieldCount = 0;
int BaseDamage = CalculateDamage(Attacker,Defender,attack);
int TotalCritDamage = (int) Math.Ceiling (BaseDamage * CriticalMultiplier);
//apply Damage to defending unit, then add to result report // results.addResult(BattleResults.resultType.MISS, 0, isCounter);
Defender.stats.status.CurrentHealth -= TotalCritDamage; // }
results.addResult(BattleResults.resultType.CRITICAL, TotalCritDamage, isCounter); // else if (hitRoll >= critThreshold) //Handle Crits
// {
} // if (Defender.stats.status.CurrentShieldCount > 1) Defender.stats.status.CurrentShieldCount--; // as is, crits ignore shields but should still tick a shield down
else if (Defender.stats.status.CurrentShieldCount > 1) // Shielded // if (Defender.stats.status.CurrentShieldCount < 0) Defender.stats.status.CurrentShieldCount = 0;
{ // int BaseDamage = CalculateDamage(Attacker,Defender,attack);
Defender.stats.status.CurrentShieldCount--; // int TotalCritDamage = (int) Math.Ceiling (BaseDamage * CriticalMultiplier);
results.addResult(BattleResults.resultType.SHIELDED,1, isCounter); // 1 siginfies 1 shield lost
}
else // normal attack
{
int BaseDamage = CalculateDamage(Attacker, Defender, attack);
//Apply damage + report to animation handler // //apply Damage to defending unit, then add to result report
Defender.stats.status.CurrentHealth -= BaseDamage; // Defender.stats.status.CurrentHealth -= TotalCritDamage;
results.addResult(BattleResults.resultType.ATTACK, BaseDamage, isCounter); // results.addResult(BattleResults.resultType.CRITICAL, TotalCritDamage, isCounter);
}
}
return;
}
private static int CalculateDamage( Unit Attacker, Unit Defender, AttackObj attack) // }
{ // else if (Defender.stats.status.CurrentShieldCount > 1) // Shielded
int damage = 0; // {
// Defender.stats.status.CurrentShieldCount--;
// results.addResult(BattleResults.resultType.SHIELDED,1, isCounter); // 1 siginfies 1 shield lost
// }
// else // normal attack
// {
// int BaseDamage = CalculateDamage(Attacker, Defender, attack);
damage += attack.BaseDamage; // //Apply damage + report to animation handler
damage += Attacker.stats.baseStats.Attack; // Defender.stats.status.CurrentHealth -= BaseDamage;
// results.addResult(BattleResults.resultType.ATTACK, BaseDamage, isCounter);
// }
// }
// return;
//}
damage -= Defender.stats.baseStats.Defense; // private static int CalculateDamage( Unit Attacker, Unit Defender, AttackObj attack)
// {
// int damage = 0;
// damage += attack.BaseDamage;
// damage += Attacker.stats.baseStats.Attack;
// damage -= Defender.stats.baseStats.Defense;
if (damage < 0) damage = 0; // if (damage < 0) damage = 0;
return damage ; // return damage ;
} // }
//}
} }
} }

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static Johnmagotchi.GameContent.Objects.Units.BattleObjects.UnitStatBlock; using static Johnmagotchi.GameContent.Objects.Units.Stats.UnitStatBlock;
namespace Johnmagotchi.GameContent.Logic namespace Johnmagotchi.GameContent.Logic
{ {

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static Johnmagotchi.Data.BattleObjects.AttackDefines; using static Johnmagotchi.Data.BattleObjects.AttackDefines;
namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects namespace Johnmagotchi.GameContent.Objects.BattleObjects
{ {
public class AttackObj public class AttackObj
{ {

View File

@ -1,16 +1,12 @@
using Johnmagotchi.Core.tools; using Johnmagotchi.Core.tools;
using Johnmagotchi.Data.BattleObjects; using Johnmagotchi.Data.BattleObjects;
using Johnmagotchi.GameContent.Units;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Johnmagotchi.Data.BattleObjects.AttackDefines; using static Johnmagotchi.Data.BattleObjects.AttackDefines;
using static Johnmagotchi.Data.BattleObjects.SupportDefines; using static Johnmagotchi.Data.BattleObjects.SupportDefines;
namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects namespace Johnmagotchi.GameContent.Objects.BattleObjects
{ {
public static class BattleObjectManager public static class BattleObjectManager
{ {
@ -48,9 +44,9 @@ namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects
public static List<AttackObj> LoadAttacks() public static List<AttackObj> LoadAttacks()
{ {
List<AttackObj> AttackList = new List<AttackObj>(); List<AttackObj> AttackList = new List<AttackObj>();
System.Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory()); Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory());
var path = "..\\..\\..\\Data\\BattleObjects\\AttackDefinitions.csv"; var path = "..\\..\\..\\Data\\BattleObjects\\AttackDefinitions.csv";
System.Console.WriteLine("path: {0} ", path); Console.WriteLine("path: {0} ", path);
// these let us resolve which column is which // these let us resolve which column is which
int IDIndex = -1; int IDIndex = -1;
@ -101,17 +97,17 @@ namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects
{ {
AttackObj attack = new AttackObj(); AttackObj attack = new AttackObj();
attack.ID = Int32.Parse(values[IDIndex]); attack.ID = int.Parse(values[IDIndex]);
attack.AttackName = values[AttackNameIndex]; attack.AttackName = values[AttackNameIndex];
attack.BaseDamage = Int32.Parse(values[BaseDamageIndex]); attack.BaseDamage = int.Parse(values[BaseDamageIndex]);
attack.BaseHitCount = Int32.Parse(values[BaseHitCountIndex]); attack.BaseHitCount = int.Parse(values[BaseHitCountIndex]);
attack.BaseSpeed = Int32.Parse(values[BaseSpeedIndex]); attack.BaseSpeed = int.Parse(values[BaseSpeedIndex]);
attack.BaseAccuracy = Int32.Parse(values[BaseAccuracyIndex]); attack.BaseAccuracy = int.Parse(values[BaseAccuracyIndex]);
attack.AttackRangeMin = Int32.Parse(values[AttackRangeMinIndex]); attack.AttackRangeMin = int.Parse(values[AttackRangeMinIndex]);
attack.AttackRangeMax = Int32.Parse(values[AttackRangeMaxIndex]); attack.AttackRangeMax = int.Parse(values[AttackRangeMaxIndex]);
attack.AttackType = AttackDefines.ParseAttackTypes(values[AttackTypeIndex]); attack.AttackType = ParseAttackTypes(values[AttackTypeIndex]);
attack.SpecialProperties = AttackDefines.ParseSpecialAttackProperties(values[SpecialPropertiesIndex]); attack.SpecialProperties = ParseSpecialAttackProperties(values[SpecialPropertiesIndex]);
attack.DamageType = AttackDefines.ParseDamageTypes(values[DamageTypeIndex]); attack.DamageType = ParseDamageTypes(values[DamageTypeIndex]);
AttackList.Add(attack); AttackList.Add(attack);
} }
@ -125,9 +121,9 @@ namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects
{ {
List<SkillObj> SkillList = new List<SkillObj>(); List<SkillObj> SkillList = new List<SkillObj>();
System.Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory()); Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory());
var path = "..\\..\\..\\Data\\BattleObjects\\SkillDefinitions.csv"; var path = "..\\..\\..\\Data\\BattleObjects\\SkillDefinitions.csv";
System.Console.WriteLine("path: {0} ", path); Console.WriteLine("path: {0} ", path);
// ID,SkillName,SkillType,Value,Description // ID,SkillName,SkillType,Value,Description
// these let us resolve which column is which // these let us resolve which column is which
@ -169,10 +165,10 @@ namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects
{ {
SkillObj skill = new SkillObj(); SkillObj skill = new SkillObj();
skill.ID = Int32.Parse(values[IDIndex]); skill.ID = int.Parse(values[IDIndex]);
skill.SkillName = values[SkillNameIndex]; skill.SkillName = values[SkillNameIndex];
skill.SkillType = SkillDefines.ParseSkillTypes(values[SkillTypeIndex]); skill.SkillType = SkillDefines.ParseSkillTypes(values[SkillTypeIndex]);
skill.Value = Int32.Parse(values[ValueIndex]); skill.Value = int.Parse(values[ValueIndex]);
skill.Description = values[DescriptionIndex]; skill.Description = values[DescriptionIndex];
SkillList.Add(skill); SkillList.Add(skill);
@ -187,9 +183,9 @@ namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects
List<SupportObj> SupportList = new List<SupportObj>(); List<SupportObj> SupportList = new List<SupportObj>();
System.Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory()); Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory());
var path = "..\\..\\..\\Data\\BattleObjects\\SupportDefinitions.csv"; var path = "..\\..\\..\\Data\\BattleObjects\\SupportDefinitions.csv";
System.Console.WriteLine("path: {0} ", path); Console.WriteLine("path: {0} ", path);
//ID,SupportName,SupportTarget,SupportType,Value,Description //ID,SupportName,SupportTarget,SupportType,Value,Description
// these let us resolve which column is which // these let us resolve which column is which
@ -234,11 +230,11 @@ namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects
{ {
SupportObj support = new SupportObj(); SupportObj support = new SupportObj();
support.ID = Int32.Parse(values[IDIndex]); support.ID = int.Parse(values[IDIndex]);
support.Name = values[SupportlNameIndex]; support.Name = values[SupportlNameIndex];
support.type = SupportDefines.ParseSupportTypes(values[SupportTypeIndex]); support.type = ParseSupportTypes(values[SupportTypeIndex]);
support.target = SupportDefines.ParseSupportTargets(values[SupportTargetIndex]); support.target = ParseSupportTargets(values[SupportTargetIndex]);
support.Value = Int32.Parse(values[ValueIndex]); support.Value = int.Parse(values[ValueIndex]);
support.Description = values[DescriptionIndex]; support.Description = values[DescriptionIndex];
SupportList.Add(support); SupportList.Add(support);

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects namespace Johnmagotchi.GameContent.Objects.BattleObjects
{ {
public class SkillObj public class SkillObj
{ {

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static Johnmagotchi.Data.BattleObjects.SupportDefines; using static Johnmagotchi.Data.BattleObjects.SupportDefines;
namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects namespace Johnmagotchi.GameContent.Objects.BattleObjects
{ {
public class SupportObj public class SupportObj
{ {

View File

@ -8,7 +8,6 @@ using System.Threading.Tasks;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using TibzGame.Core.ScreenManager; using TibzGame.Core.ScreenManager;
using Johnmagotchi.GameContent.Units;
using Johnmagotchi.Core.tools; using Johnmagotchi.Core.tools;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using Johnmagotchi.GameContent.Objects.Units; using Johnmagotchi.GameContent.Objects.Units;
@ -22,16 +21,14 @@ namespace Johnmagotchi.GameContent.Objects
public int height{ get; set; } public int height{ get; set; }
public string serializedMapTiles{ get; set; } public string serializedMapTiles{ get; set; }
public string serializedPlayerUnits { get; set; } public string serializedUnits { get; set; }
public string serializedEnemyUnits{ get; set; }
public string serializedNpcUnits { get; set; }
private MapTile [,] MapTileGrid; private MapTile [,] MapTileGrid;
private List<Unit> playerUnits; private List<Unit> Units;
private List<Unit> enemyUnits; //private List<Unit> playerUnits;
private List<Unit> npcUnits; //private List<Unit> enemyUnits;
//private List<Unit> npcUnits;
private SpriteBatch _spriteBatch; private SpriteBatch _spriteBatch;
private ScreenManager _screenManager; private ScreenManager _screenManager;
@ -52,9 +49,10 @@ namespace Johnmagotchi.GameContent.Objects
this.height = h; // default min height (shooting for 360 x 640 res, 40x40 pixel grid) this.height = h; // default min height (shooting for 360 x 640 res, 40x40 pixel grid)
this.width = w; this.width = w;
MapTileGrid = new MapTile[width,height]; MapTileGrid = new MapTile[width,height];
this.playerUnits = new List<Unit>(); this.Units = new List<Unit>();
this.npcUnits = new List<Unit>(); //this.playerUnits = new List<Unit>();
this.enemyUnits = new List<Unit>(); //this.npcUnits = new List<Unit>();
//this.enemyUnits = new List<Unit>();
} }
public void Init(ScreenManager ScreenManager){ public void Init(ScreenManager ScreenManager){
@ -75,15 +73,7 @@ namespace Johnmagotchi.GameContent.Objects
public void Update() public void Update()
{ {
foreach (Unit unit in playerUnits) foreach (Unit unit in Units)
{
unit.Update();
}
foreach (Unit unit in enemyUnits)
{
unit.Update();
}
foreach (Unit unit in npcUnits)
{ {
unit.Update(); unit.Update();
} }
@ -161,24 +151,11 @@ namespace Johnmagotchi.GameContent.Objects
public void DrawUnits(int xOffset, int yOffset) { public void DrawUnits(int xOffset, int yOffset) {
foreach(Unit unit in Units) {
foreach(Unit unit in playerUnits) {
int xLocation = (unit.xPos * MapTile.TILE_WIDTH_PX) + xOffset; int xLocation = (unit.xPos * MapTile.TILE_WIDTH_PX) + xOffset;
int yLocation = (unit.yPos * MapTile.TILE_HEIGHT_PX) + yOffset; int yLocation = (unit.yPos * MapTile.TILE_HEIGHT_PX) + yOffset;
unit.DrawAt( xLocation, yLocation); unit.DrawAt( xLocation, yLocation);
} }
foreach (Unit unit in enemyUnits)
{
int xLocation = (unit.xPos * MapTile.TILE_WIDTH_PX) + xOffset;
int yLocation = (unit.yPos * MapTile.TILE_HEIGHT_PX) + yOffset;
unit.DrawAt( xLocation, yLocation);
}
foreach (Unit unit in npcUnits)
{
int xLocation = (unit.xPos * MapTile.TILE_WIDTH_PX) + xOffset;
int yLocation = (unit.yPos * MapTile.TILE_HEIGHT_PX) + yOffset;
unit.DrawAt(xLocation, yLocation);
}
} }
public void ChangeTileType(int x, int y, TileType newType) public void ChangeTileType(int x, int y, TileType newType)
@ -226,62 +203,30 @@ namespace Johnmagotchi.GameContent.Objects
} }
public void SerializeUnitData() { public void SerializeUnitData() {
List<string> player = new List<string>(); List<string> units_str = new List<string>();
List<string> enemy = new List<string>();
List<string> npc = new List<string>(); foreach (Unit unit in Units) {
units_str.Add(unit.GetAsSerialized());
foreach (Unit unit in playerUnits) {
player.Add(unit.GetAsSerialized());
} }
foreach (Unit unit in enemyUnits) {
enemy.Add(unit.GetAsSerialized()); serializedUnits = JsonSerializer.Serialize(units_str);
} TibzLog.Debug("Units: " + Units.Count);
foreach (Unit unit in npcUnits)
{
npc.Add(unit.GetAsSerialized());
}
serializedPlayerUnits = JsonSerializer.Serialize(player);
serializedEnemyUnits = JsonSerializer.Serialize(enemy);
serializedNpcUnits = JsonSerializer.Serialize(npc);
TibzLog.Debug("P:" + player.Count + " E:" + enemy.Count + " N:" + npc.Count);
} }
public void DeserializeUnitData() { public void DeserializeUnitData() {
TibzLog.Debug("Deserializing unit data"); TibzLog.Debug("Deserializing unit data");
List<Unit> OutPlayerUnits = new List<Unit>(); List<Unit> outUnits = new List<Unit>();
List<Unit> OutEnemyUnits = new List<Unit>();
List<Unit> OutNpcUnits = new List<Unit>();
List<string> players = JsonSerializer.Deserialize<List<string>>(serializedPlayerUnits); List<string> unitsString = JsonSerializer.Deserialize<List<string>>(serializedUnits);
List<string> enemies = JsonSerializer.Deserialize<List<string>>(serializedEnemyUnits);
List<string> npcs = JsonSerializer.Deserialize<List<string>>(serializedNpcUnits);
foreach(string entry in players) { foreach(string entry in unitsString) {
Unit newUnit = new Unit(entry); Unit newUnit = new Unit(entry);
TibzLog.Debug(JsonSerializer.Serialize(newUnit)); TibzLog.Debug(JsonSerializer.Serialize(newUnit));
OutPlayerUnits.Add(newUnit); // makes new instance from serialized string outUnits.Add(newUnit); // makes new instance from serialized string
newUnit.InitSprite(_screenManager); newUnit.InitSprite(_screenManager);
} }
foreach (string entry in enemies) Units = outUnits;
{
Unit newUnit = new Unit(entry);
OutEnemyUnits.Add(newUnit); // makes new instance from serialized string
newUnit.InitSprite(_screenManager);
}
foreach (string entry in npcs)
{
Unit newUnit = new Unit(entry);
OutNpcUnits.Add(newUnit); // makes new instance from serialized string
newUnit.InitSprite(_screenManager);
}
playerUnits = OutPlayerUnits;
enemyUnits = OutEnemyUnits;
npcUnits = OutNpcUnits;
TibzLog.Debug("P:" + playerUnits.Count + " E:" + enemyUnits.Count + " N:" + npcUnits.Count);
} }
public void AddPlayerUnit(Unit unitRef, int xpos, int ypos) public void AddPlayerUnit(Unit unitRef, int xpos, int ypos)
@ -295,25 +240,8 @@ namespace Johnmagotchi.GameContent.Objects
unit.SetShaderSet(Unit.SpriteShaderSets.PLAYER_NORMAL); unit.SetShaderSet(Unit.SpriteShaderSets.PLAYER_NORMAL);
unit.xPos = xpos; unit.xPos = xpos;
unit.yPos = ypos; unit.yPos = ypos;
//if (unit.isUnique == true) unit.stats.status.team = Objects.Units.Stats.UnitCurrentStatus.UnitTeam.PLAYER;
//{ Units.Add(unit);
// //check then replace
// for (int i = 0; i < playerUnits.Count; i++)
// {
// if (playerUnits[i].id == unit.id )
// {
// playerUnits[i].xPos = xpos;
// playerUnits[i].yPos = ypos;
// return; // dont add
// }
// }
// playerUnits.Add(unit); // else add
//}
//else { playerUnits.Add(unit);
//}
playerUnits.Add(unit);
unit.stats.status.team = Units.BattleObjects.UnitCurrentStatus.UnitTeam.PLAYER;
unit.InitSprite(_screenManager); unit.InitSprite(_screenManager);
} }
@ -328,24 +256,8 @@ namespace Johnmagotchi.GameContent.Objects
unit.SetShaderSet(Unit.SpriteShaderSets.ENEMY_NORMAL); unit.SetShaderSet(Unit.SpriteShaderSets.ENEMY_NORMAL);
unit.xPos = xpos; unit.xPos = xpos;
unit.yPos = ypos; unit.yPos = ypos;
//if (unit.isUnique == true) unit.stats.status.team = Objects.Units.Stats.UnitCurrentStatus.UnitTeam.ENEMY;
//{ Units.Add(unit);
// //check then replace
// for (int i = 0; i < enemyUnits.Count; i++)
// {
// if (enemyUnits[i].id == unit.id)
// {
// enemyUnits[i].xPos = xpos;
// enemyUnits[i].yPos = ypos;
// return; // dont add
// }
// }
// enemyUnits.Add(unit); // else add
//}
//else
//{
enemyUnits.Add(unit);
unit.stats.status.team = Units.BattleObjects.UnitCurrentStatus.UnitTeam.ENEMY;
unit.InitSprite(_screenManager); unit.InitSprite(_screenManager);
} }
@ -361,68 +273,29 @@ namespace Johnmagotchi.GameContent.Objects
unit.SetShaderSet(Unit.SpriteShaderSets.NPC_NORMAL); unit.SetShaderSet(Unit.SpriteShaderSets.NPC_NORMAL);
unit.xPos = xpos; unit.xPos = xpos;
unit.yPos = ypos; unit.yPos = ypos;
unit.stats.status.team = Objects.Units.Stats.UnitCurrentStatus.UnitTeam.NPC;
//if (unit.isUnique == true) Units.Add(unit);
//{
// //check then replace
// for (int i = 0; i < npcUnits.Count; i++)
// {
// if (npcUnits[i].id == unit.id)
// {
// enemyUnits[i] = unit;
// return; // dont add
// }
// }
// npcUnits.Add(unit); // else add
//}
//else
//{
npcUnits.Add(unit);
// }
unit.InitSprite(_screenManager); unit.InitSprite(_screenManager);
unit.stats.status.team = Units.BattleObjects.UnitCurrentStatus.UnitTeam.NPC;
TibzLog.Debug("NPC obj count: {0}", npcUnits.Count);
} }
public void deleteUnit(Unit unitRef) { public void deleteUnit(Unit unitRef) {
int removePlayerIndex = -1; int removeUnitIndex = -1;
int removeEnemyIndex = -1;
int removeNpcIndex = -1;
for (int i = 0; i < playerUnits.Count; i++) for (int i = 0; i < Units.Count; i++)
{ {
if (unitRef.internalID == playerUnits[i].internalID) if (unitRef.internalID == Units[i].internalID)
{ {
removePlayerIndex = i; removeUnitIndex = i;
break; break;
} }
} }
for (int i = 0; i < enemyUnits.Count; i++)
{ if (removeUnitIndex != -1) { Units.RemoveAt(removeUnitIndex); }
if (unitRef.internalID == enemyUnits[i].internalID)
{
removeEnemyIndex = i;
break;
}
}
for (int i = 0; i < npcUnits.Count; i++)
{
if (unitRef.internalID == npcUnits[i].internalID)
{
removeNpcIndex = i;
break;
}
}
if (removePlayerIndex != -1) { playerUnits.RemoveAt(removePlayerIndex); }
if (removeEnemyIndex != -1) { enemyUnits.RemoveAt(removeEnemyIndex); }
if (removeNpcIndex != -1) { npcUnits.RemoveAt(removeNpcIndex); }
} }
private bool CheckIfUnitCanBePlaced(Unit unit, int x, int y) { private bool CheckIfUnitCanBePlaced(Unit unit, int x, int y) {
if (x < 0 || y < 0 ||x > width || y>height) return false;
if (MapTileGrid[x,y].Type == TileType.SEA ) { // add a && unit.Traversal type or whatever, so we check if this unit CAN stand on said tile. if (MapTileGrid[x,y].Type == TileType.SEA ) { // add a && unit.Traversal type or whatever, so we check if this unit CAN stand on said tile.
return false; return false;
} }
@ -432,52 +305,28 @@ namespace Johnmagotchi.GameContent.Objects
} }
public bool CheckIfAnyUnits(int x, int y) { public bool CheckIfAnyUnits(int CursorX, int CursorY) {
return CheckIfPlayerUnits(x, y) || CheckIfEnemyUnits(x,y)|| CheckIfNpcUnits(x,y) ; foreach (Unit Unit in Units)
}
public bool CheckIfPlayerUnits(int CursorX, int CursorY)
{
foreach (Unit Unit in playerUnits) {
if (Unit.xPos == CursorX && Unit.yPos == CursorY) { return true; }
}
return false;
}
public bool CheckIfEnemyUnits(int CursorX, int CursorY)
{
foreach (Unit Unit in enemyUnits)
{
if (Unit.xPos == CursorX && Unit.yPos == CursorY) { return true; }
}
return false;
}
public bool CheckIfNpcUnits(int CursorX, int CursorY)
{
foreach (Unit Unit in npcUnits)
{ {
if (Unit.xPos == CursorX && Unit.yPos == CursorY) { return true; } if (Unit.xPos == CursorX && Unit.yPos == CursorY) { return true; }
} }
return false; return false;
} }
public Unit getUnitAtLocation(int CursorX, int CursorY) { public Unit getUnitAtLocation(int CursorX, int CursorY) {
foreach (Unit Unit in playerUnits) foreach (Unit Unit in Units)
{
if (Unit.xPos == CursorX && Unit.yPos == CursorY) { return Unit; }
}
foreach (Unit Unit in enemyUnits)
{
if (Unit.xPos == CursorX && Unit.yPos == CursorY) { return Unit; }
}
foreach (Unit Unit in npcUnits)
{ {
if (Unit.xPos == CursorX && Unit.yPos == CursorY) { return Unit; } if (Unit.xPos == CursorX && Unit.yPos == CursorY) { return Unit; }
} }
return null; return null;
} }
public void moveUnit(Unit unitcopy, int x, int y) public void moveUnit(Unit unitcopy, int x, int y)
{ {
foreach (Unit Unit in playerUnits) foreach (Unit Unit in Units)
{ {
if (Unit.internalID == unitcopy.internalID) if (Unit.internalID == unitcopy.internalID)
{ {
@ -485,14 +334,7 @@ namespace Johnmagotchi.GameContent.Objects
Unit.yPos = y; Unit.yPos = y;
} }
} }
foreach (Unit Unit in enemyUnits)
{
if (Unit.internalID == unitcopy.internalID) { }
}
foreach (Unit Unit in npcUnits)
{
if (Unit.internalID == unitcopy.internalID) { }
}
} }
public MapTile getTile(int x, int y) { public MapTile getTile(int x, int y) {
@ -514,9 +356,7 @@ namespace Johnmagotchi.GameContent.Objects
clone.serializedMapTiles = this.serializedMapTiles; clone.serializedMapTiles = this.serializedMapTiles;
clone.deserializeMapTiles(); clone.deserializeMapTiles();
clone.serializedPlayerUnits = this.serializedPlayerUnits; clone.serializedUnits = this.serializedUnits;
clone.serializedNpcUnits = this.serializedNpcUnits;
clone.serializedEnemyUnits = this.serializedEnemyUnits;
clone.DeserializeUnitData(); clone.DeserializeUnitData();
return clone; return clone;

View File

@ -1,7 +1,6 @@
using Johnmagotchi.Core.tools; using Johnmagotchi.Core.tools;
using Johnmagotchi.GameContent.Logic; using Johnmagotchi.GameContent.Logic;
using Johnmagotchi.GameContent.Objects.Units; using Johnmagotchi.GameContent.Objects.Units;
using Johnmagotchi.GameContent.Units;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms.VisualStyles; using System.Windows.Forms.VisualStyles;
@ -145,9 +144,9 @@ namespace Johnmagotchi.GameContent.Objects.Maps
Unit targetUnit = currentMap.getUnitAtLocation(x, y); Unit targetUnit = currentMap.getUnitAtLocation(x, y);
if (targetUnit != null) { if (targetUnit != null) {
if ( if (
(selectedUnit.stats.status.team == Units.BattleObjects.UnitCurrentStatus.UnitTeam.PLAYER && targetUnit.stats.status.team == Units.BattleObjects.UnitCurrentStatus.UnitTeam.ENEMY) || (selectedUnit.stats.status.team == Units.Stats.UnitCurrentStatus.UnitTeam.PLAYER && targetUnit.stats.status.team == Units.Stats.UnitCurrentStatus.UnitTeam.ENEMY) ||
(selectedUnit.stats.status.team == Units.BattleObjects.UnitCurrentStatus.UnitTeam.ENEMY && (targetUnit.stats.status.team == Units.BattleObjects.UnitCurrentStatus.UnitTeam.PLAYER || (selectedUnit.stats.status.team == Units.Stats.UnitCurrentStatus.UnitTeam.ENEMY && (targetUnit.stats.status.team == Units.Stats.UnitCurrentStatus.UnitTeam.PLAYER ||
targetUnit.stats.status.team == Units.BattleObjects.UnitCurrentStatus.UnitTeam.NPC)) targetUnit.stats.status.team == Units.Stats.UnitCurrentStatus.UnitTeam.NPC))
) )
{ {
return 0; return 0;

View File

@ -1,6 +1,5 @@
using Johnmagotchi.Core.tools; using Johnmagotchi.Core.tools;
using Johnmagotchi.GameContent.Objects.Units; using Johnmagotchi.GameContent.Objects.Units;
using Johnmagotchi.GameContent.Units;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
@ -63,11 +62,11 @@ namespace Johnmagotchi.GameContent.Objects.UI
if (HighlightedUnit == null) { return; } if (HighlightedUnit == null) { return; }
Texture2D texture = UnitDisplayTexture; Texture2D texture = UnitDisplayTexture;
if (HighlightedUnit.stats.status.team == Units.BattleObjects.UnitCurrentStatus.UnitTeam.ENEMY) if (HighlightedUnit.stats.status.team == Units.Stats.UnitCurrentStatus.UnitTeam.ENEMY)
{ {
texture = EnemyDisplayTexture; texture = EnemyDisplayTexture;
} }
if (HighlightedUnit.stats.status.team == Units.BattleObjects.UnitCurrentStatus.UnitTeam.NPC) if (HighlightedUnit.stats.status.team == Units.Stats.UnitCurrentStatus.UnitTeam.NPC)
{ {
texture = NpcDisplayTexture; texture = NpcDisplayTexture;
} }

View File

@ -1,170 +0,0 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using Johnmagotchi.Core.tools;
using System.Collections;
using System.Net.Http.Headers;
using static Johnmagotchi.GameContent.Objects.Units.BattleObjects.UnitStatBlock;
using Johnmagotchi.GameContent.Objects.Units.Loadouts.PlayerClasses;
using Johnmagotchi.GameContent.Objects.Units;
namespace Johnmagotchi.GameContent.Units
{
public class UnitLoader
{
public static List<string> GetTest() {
// MAC OS also prly Linux - var path = Path.Combine(Directory.GetCurrentDirectory(), "GameContent/Objects/Units/UnitDefines.csv");
//System.Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory());
//var path = "..\\..\\..\\GameContent\\Objects\\Units\\UnitDefines.csv";
List<string> listA = new List<string>();
return listA;
}
//public static List<UnitObject> LoadBaseUnits() {
// List<UnitObject> unitList = new List<UnitObject>();
// System.Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory());
// var path = "..\\..\\..\\Data\\BattleObjects\\UnitDefinitions.csv";
// List<string> listA = new List<string>();
// List<string> listB = new List<string>();
// System.Console.WriteLine("path: {0} ", path);
// // these let us resolve which column is which
// int IdIndex = -1;
// int NameIndex = -1;
// int ClassIndex = -1;
// int isUniqueIndex = -1;
// int HealthIndex = -1;
// int AttackIndex = -1;
// int DefenseIndex = -1;
// int SpeedIndex = -1;
// int MovementIndex = -1;
// int MovementTypeIndex = -1;
// bool AreColumnIndexesSet = false;
// using (var reader = new StreamReader(path))
// {
// while (!reader.EndOfStream)
// {
// var line = reader.ReadLine();
// var values = line.Split(',');
// if (AreColumnIndexesSet == false)
// {
// //These strings MUST match /GameContent/Data/UnitDefines.CSV
// // That file MUST have these in the first row.
// for (int i = 0; i < values.Length; i++) {
// if (values[i].Trim() == "ID") { IdIndex = i; }
// if (values[i].Trim() == "NAME") { NameIndex = i; }
// if (values[i].Trim() == "CLASS") { ClassIndex = i; }
// if (values[i].Trim() == "IS_UNIQUE") { isUniqueIndex = i; }
// if (values[i].Trim() == "HEALTH") { HealthIndex = i; }
// if (values[i].Trim() == "ATTACK") { AttackIndex = i; }
// if (values[i].Trim() == "DEFENSE") { DefenseIndex = i; }
// if (values[i].Trim() == "SPEED") { SpeedIndex = i; }
// if (values[i].Trim() == "MOVEMENT") { MovementIndex = i; }
// if (values[i].Trim() == "MOVEMENT_TYPE") { MovementTypeIndex = i; }
// }
// AreColumnIndexesSet = true;
// }
// else {
// UnitObject unit = new UnitObject();
// unit.id = Int32.Parse(values[IdIndex]);
// unit.name = unit.stats = values[NameIndex];
// unit.playerClassEnum = PlayerClass.GetClassFromShortHand(values[ClassIndex]);
// unit.isUnique = (values[isUniqueIndex].ToLower() == "true");
// unit.stats.MaxHealth = Int32.Parse(values[HealthIndex]);
// unit.stats.Attack = Int32.Parse(values[AttackIndex]);
// unit.stats.Defense = Int32.Parse(values[DefenseIndex]);
// unit.stats.Speed = Int32.Parse(values[SpeedIndex]);
// unit.stats.Movement = Int32.Parse(values[MovementIndex]);
// unit.stats.setMovementTypeFromFile(values[MovementTypeIndex]);
// unitList.Add(unit);
// }
// }
// }
// return unitList;
//}
public static List <Unit> LoadUnitList ()
{
List<Unit> unitList = new List<Unit>();
System.Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory());
var path = "..\\..\\..\\Data\\BattleObjects\\UnitDefinitions.csv";
System.Console.WriteLine("path: {0} ", path);
// these let us resolve which column is which
int IdIndex = -1;
int NameIndex = -1;
int ClassIndex = -1;
int isUniqueIndex = -1;
int HealthIndex = -1;
int AttackIndex = -1;
int DefenseIndex = -1;
int SpeedIndex = -1;
int MovementIndex = -1;
int MovementTypeIndex = -1;
bool AreColumnIndexesSet = false;
using (var reader = new StreamReader(path))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
if (AreColumnIndexesSet == false)
{
//These strings MUST match /GameContent/Data/UnitDefines.CSV
// That file MUST have these in the first row.
for (int i = 0; i < values.Length; i++)
{
if (values[i].Trim() == "ID") { IdIndex = i; }
if (values[i].Trim() == "NAME") { NameIndex = i; }
if (values[i].Trim() == "CLASS") { ClassIndex = i; }
if (values[i].Trim() == "IS_UNIQUE") { isUniqueIndex = i; }
if (values[i].Trim() == "HEALTH") { HealthIndex = i; }
if (values[i].Trim() == "ATTACK") { AttackIndex = i; }
if (values[i].Trim() == "DEFENSE") { DefenseIndex = i; }
if (values[i].Trim() == "SPEED") { SpeedIndex = i; }
if (values[i].Trim() == "MOVEMENT") { MovementIndex = i; }
if (values[i].Trim() == "MOVEMENT_TYPE") { MovementTypeIndex = i; }
}
AreColumnIndexesSet = true;
}
else
{
Unit unit = new Unit();
unit.UnitID = Int32.Parse(values[IdIndex]);
unit.stats.classId = PlayerClass.GetClassFromShortHand(values[ClassIndex]);
// unit.isUnique = (values[isUniqueIndex].ToLower() == "true");
unit.name = unit.stats.Name = values[NameIndex];
unit.stats.baseStats.MaxHealth = Int32.Parse(values[HealthIndex]);
unit.stats.baseStats.Attack = Int32.Parse(values[AttackIndex]);
unit.stats.baseStats.Defense = Int32.Parse(values[DefenseIndex]);
unit.stats.baseStats.Speed = Int32.Parse(values[SpeedIndex]);
unit.stats.baseStats.Movement = Int32.Parse(values[MovementIndex]);
unit.stats.baseStats.setMovementTypeFromFile(values[MovementTypeIndex]);
unitList.Add(unit);
}
}
}
return unitList;
}
}
}

View File

@ -1,226 +0,0 @@
using Johnmagotchi.Core.tools;
using Johnmagotchi.GameContent.Objects;
using Johnmagotchi.GameContent.Objects.Units.BattleObjects;
using Johnmagotchi.GameContent.Objects.Units.Loadouts;
using Johnmagotchi.GameContent.Objects.Units.Loadouts.PlayerClasses;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Security.Cryptography.X509Certificates;
using System.Text.Json;
using System.Text.Json.Serialization;
using TibzGame.Core.ScreenManager;
using static Johnmagotchi.GameContent.Objects.Units.Loadouts.PlayerClasses.PlayerClass;
namespace Johnmagotchi.GameContent.Units
{
/// <summary>
/// TO DO -- THIS SHOULD BE DELETED AFTER REFACTOR TO *BASE UNIT*
/// </summary>
public class UnitObject{
//defined stats
public int internalID; // used to reference this object internally
public int id { get; set; } // used to reference this unit as "Byleth" or "Marth" or whatever, you know?
public string name { get; set; }
// REMOVING TEMPORARILY
public UnitStatBlock stats { set; get; }
public UnitCurrentStatus currentStatus { get; set; }
public bool isUnique { set; get; }
public UnitTeam team { set; get; }
public PlayerClassType playerClassEnum { get; set; }
// Stats for battle screens
public bool isTurnOver { set; get; }
// public statusEnum status {get;set;}
public int xPos { set; get; }
public int yPos { set; get; }
PlayerClass playerClassInstance;
public UnitLoadout UnitLoadout { get; set; }
public string serializedUnitLoadout { get; set;}
// -------------------------------------------------------------------------------------------------------------
//drawing and state management
public SpriteShaderSets shaderSet;
public Texture2D sprite;
private Effect TurnEndedEffect;
private SpriteBatch spriteBatch;
private ScreenManager _screenManager;
private bool IsInit;
// DEBUG VARS
// this needs to be expanded for attacks/ items eventually, does not need saved atm
public int DirectAttackRangeMin = 2;
public int DirectAttackRangeMax = 4;
public int IndirectAttackRangeMin;
public int IndirectAttackRangeMax;
public enum UnitTeam
{
PLAYER,
ENEMY,
NPC
}
public enum SpriteShaderSets {
PLAYER_NORMAL,
ENEMY_NORMAL,
NPC_NORMAL
}
public UnitObject(){
IsInit = false;
xPos = 0;
yPos = 0;
stats = new UnitStatBlock();
currentStatus = new UnitCurrentStatus(stats);
// playerClassInstance = new PlayerClass(playerClassEnum);
}
public UnitObject(UnitObject template) {
IsInit = false;
CopyFromTemplate(template);
isTurnOver = false;
playerClassInstance = new PlayerClass(playerClassEnum);
UnitLoadout = new UnitLoadout(playerClassEnum);
currentStatus = new UnitCurrentStatus(stats);
}
public UnitObject(string serializedData)
{
IsInit = false;
SetFromSerialized(serializedData);
//this.currentStatus = new UnitCurrentStatus(stats);
this.UnitLoadout = new UnitLoadout(playerClassEnum);
}
public string GetAsSerialized()
{
string json = JsonSerializer.Serialize(this);
return json;
}
public void SetFromSerialized(string data)
{
UnitObject temp = JsonSerializer.Deserialize<UnitObject>(data);
CopyFromTemplate(temp); // get base stats
isTurnOver = temp.isTurnOver;
return ;
}
public void setTeam(UnitTeam team)
{
this.team = team;
this.ReinitSprite();
}
public void SetShaderSet(SpriteShaderSets inSet) {
shaderSet = inSet;
}
public void InitSprite(ScreenManager screenManager, UnitTeam team) {
_screenManager = screenManager;
spriteBatch = new SpriteBatch(screenManager.GraphicsDevice);
this.team = team;
string path = getSpriteTexturePath();
sprite = screenManager.contentRef.Load<Texture2D>(path);
this.internalID = screenManager.getUnitId();
TurnEndedEffect = screenManager.contentRef.Load<Effect>("Shaders/Units/UnitTurnEnded_S");
IsInit = true;
}
public void ReinitSprite()
{
spriteBatch = new SpriteBatch(_screenManager.GraphicsDevice);
string path = getSpriteTexturePath();
sprite = _screenManager.contentRef.Load<Texture2D>(path);
IsInit = true;
}
public void Update() {
}
public void CopyFromTemplate(UnitObject template)
{
this.id = template.id;
this.name = template.name;
this.stats = template.stats;
this.xPos = template.xPos;
this.yPos = template.yPos;
this.isUnique = template.isUnique;
this.playerClassEnum = template.playerClassEnum;
this.currentStatus = template.currentStatus;
//this.sprite = template.sprite;
}
public void DrawAt( int x, int y) {
if (IsInit == false) return;
SpriteEffects effects = getSpriteShaderEffects(shaderSet);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp);
// all rectangles should do the scaling from world coordinates to screen coordinates
Rectangle rect = _screenManager.GetScaledRectangle(x, y, MapTile.TILE_WIDTH_PX, MapTile.TILE_HEIGHT_PX);
//TibzLog.Debug("Scaled xPos: {0}, yPos: {1}" , tileRect.X, tileRect.Y);
// Texture2D currentTexture;
if (isTurnOver) {
//apply shader
TurnEndedEffect.CurrentTechnique.Passes[0].Apply();
}
spriteBatch.Draw(
sprite, rect, null, Color.White, 0, new Vector2(0, 0),
effects, 1);
spriteBatch.End();
}
private SpriteEffects getSpriteShaderEffects(SpriteShaderSets shaderEnum) {
return SpriteEffects.None;
}
public string getSpriteTexturePath()
{
if (team == UnitTeam.PLAYER)
{
return "Units/unit-test";
}
if (team == UnitTeam.ENEMY)
{
return "Units/unit-test-enemy";
}
if (team == UnitTeam.NPC)
{
return "Units/unit-test-npc";
}
return "Units/unit-test";
}
}
}

View File

@ -1,6 +1,4 @@
using Johnmagotchi.GameContent.Objects.Units.BattleObjects; using Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts;
using Johnmagotchi.GameContent.Objects.Units.Loadouts;
using Johnmagotchi.GameContent.Objects.Units.Loadouts.PlayerClasses;
using Johnmagotchi.GameContent.Objects.Units.Stats; using Johnmagotchi.GameContent.Objects.Units.Stats;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
@ -11,8 +9,9 @@ using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using TibzGame.Core.ScreenManager; using TibzGame.Core.ScreenManager;
using static Johnmagotchi.GameContent.Objects.Units.BattleObjects.UnitCurrentStatus; using static Johnmagotchi.GameContent.Objects.Units.Stats.UnitCurrentStatus;
using static Johnmagotchi.GameContent.Objects.Units.Loadouts.PlayerClasses.PlayerClass; using static Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts.PlayerClasses.PlayerClass;
using Johnmagotchi.Core.tools;
namespace Johnmagotchi.GameContent.Objects.Units.GameLogic namespace Johnmagotchi.GameContent.Objects.Units.GameLogic
{ {
@ -31,11 +30,8 @@ namespace Johnmagotchi.GameContent.Objects.Units.GameLogic
public int xPos { set; get; } public int xPos { set; get; }
public int yPos { set; get; } public int yPos { set; get; }
// ------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------
//drawing and state management //drawing and state management
public SpriteShaderSets shaderSet; public SpriteShaderSets shaderSet;
public Texture2D sprite; public Texture2D sprite;
@ -64,8 +60,20 @@ namespace Johnmagotchi.GameContent.Objects.Units.GameLogic
xPos = 0; xPos = 0;
yPos = 0; yPos = 0;
} }
public BaseUnitGameObject(Unit template)
{
IsInit = false;
hasStats = false;
xPos = 0;
yPos = 0;
name = template.name;
playerClassEnum = template.playerClassEnum;
public void SetStats(UnitStats newStats) TibzLog.Debug("set from template- " + playerClassEnum );
}
public void SetStats(UnitStats newStats)
{ {
stats = newStats; stats = newStats;
hasStats = true; hasStats = true;

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Johnmagotchi.GameContent.Objects.Units.Loadouts namespace Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts
{ {
public class LoadoutModule public class LoadoutModule
{ {

View File

@ -1,10 +1,10 @@
using Johnmagotchi.Core.tools; using Johnmagotchi.Core.tools;
using Johnmagotchi.GameContent.Objects.Units.BattleObjects; using Johnmagotchi.GameContent.Objects.BattleObjects;
using Johnmagotchi.GameContent.Objects.Units.Loadouts; using Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Johnmagotchi.GameContent.Objects.Units.Loadouts.PlayerClasses namespace Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts.PlayerClasses
{ {
public class PlayerClass public class PlayerClass
{ {
@ -245,7 +245,7 @@ namespace Johnmagotchi.GameContent.Objects.Units.Loadouts.PlayerClasses
} }
if (attack != null) if (attack != null)
this.ClassAttacks.Add(attack); ClassAttacks.Add(attack);
} }
} }

View File

@ -1,15 +1,15 @@
using Johnmagotchi.Core.tools; using Johnmagotchi.Core.tools;
using Johnmagotchi.GameContent.Objects.Units.BattleObjects; using Johnmagotchi.GameContent.Objects.BattleObjects;
using Johnmagotchi.GameContent.Objects.Units.Loadouts.PlayerClasses; using Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts.PlayerClasses;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
using static Johnmagotchi.GameContent.Objects.Units.Loadouts.PlayerClasses.PlayerClass; using static Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts.PlayerClasses.PlayerClass;
namespace Johnmagotchi.GameContent.Objects.Units.Loadouts namespace Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts
{ {
public class UnitLoadout public class UnitLoadout
{ {
@ -95,9 +95,9 @@ namespace Johnmagotchi.GameContent.Objects.Units.Loadouts
} }
public void saveAllToCSV() { public void saveAllToCSV() {
AvailibleAttackIDsCSV = String.Join(",", AvailableAttacks.Select(atk => atk.ID).ToArray()); AvailibleAttackIDsCSV = string.Join(",", AvailableAttacks.Select(atk => atk.ID).ToArray());
AvailaibeSupportIDsCSV = String.Join(",", AvailableSupports.Select(spt => spt.ID).ToArray()); AvailaibeSupportIDsCSV = string.Join(",", AvailableSupports.Select(spt => spt.ID).ToArray());
ActiveSkillsIDsCSV = String.Join(",", ActiveSkills.Select(skill => skill.ID).ToArray()); ActiveSkillsIDsCSV = string.Join(",", ActiveSkills.Select(skill => skill.ID).ToArray());
} }
} }
} }

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Johnmagotchi.GameContent.Objects.Units.Loadouts namespace Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts
{ {
internal class UnitLoadoutManager internal class UnitLoadoutManager
{ {

View File

@ -1,5 +1,4 @@
using Johnmagotchi.Core.tools; using Johnmagotchi.Core.tools;
using Johnmagotchi.GameContent.Units;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -8,7 +7,7 @@ using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects namespace Johnmagotchi.GameContent.Objects.Units.Stats
{ {
public class UnitCurrentStatus public class UnitCurrentStatus
{ {
@ -35,10 +34,10 @@ namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects
this.CurrentShieldCount = CurrentShieldCount; this.CurrentShieldCount = CurrentShieldCount;
} }
public void setFromSerialized(UnitObject temp, string data) { public void setFromSerialized(Unit temp, string data) {
UnitCurrentStatus parsedData = JsonSerializer.Deserialize<UnitCurrentStatus>(data); UnitCurrentStatus parsedData = JsonSerializer.Deserialize<UnitCurrentStatus>(data);
temp.currentStatus.CurrentHealth = parsedData.CurrentHealth;// Update current stats // temp.currentStatus.CurrentHealth = parsedData.CurrentHealth;// Update current stats
CurrentShieldCount = 0; CurrentShieldCount = 0;
TibzLog.Debug("HP on deserialized: " + parsedData.CurrentHealth); TibzLog.Debug("HP on deserialized: " + parsedData.CurrentHealth);
} }

View File

@ -1,4 +1,4 @@
namespace Johnmagotchi.GameContent.Objects.Units.BattleObjects namespace Johnmagotchi.GameContent.Objects.Units.Stats
{ {
public class UnitStatBlock{ public class UnitStatBlock{

View File

@ -1,11 +1,10 @@
using Johnmagotchi.GameContent.Objects.Units.BattleObjects; using Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts;
using Johnmagotchi.GameContent.Objects.Units.Loadouts;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static Johnmagotchi.GameContent.Objects.Units.Loadouts.PlayerClasses.PlayerClass; using static Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts.PlayerClasses.PlayerClass;
namespace Johnmagotchi.GameContent.Objects.Units.Stats namespace Johnmagotchi.GameContent.Objects.Units.Stats
{ {

View File

@ -1,7 +1,6 @@
using Johnmagotchi.GameContent.Objects.Units.GameLogic; using Johnmagotchi.GameContent.Objects.Units.GameLogic;
using Johnmagotchi.GameContent.Objects.Units.Loadouts; using Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts;
using Johnmagotchi.GameContent.Objects.Units.Stats; using Johnmagotchi.GameContent.Objects.Units.Stats;
using Johnmagotchi.GameContent.Units;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -23,7 +22,7 @@ namespace Johnmagotchi.GameContent.Objects.Units
this.SetStats(new UnitStats()); this.SetStats(new UnitStats());
} }
public Unit(Unit template) : base() public Unit(Unit template) : base(template)
{ {
SetStats(template.GetStats()); SetStats(template.GetStats());
} }

View File

@ -0,0 +1,98 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using Johnmagotchi.Core.tools;
using System.Collections;
using System.Net.Http.Headers;
using static Johnmagotchi.GameContent.Objects.Units.Stats.UnitStatBlock;
using Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts.PlayerClasses;
namespace Johnmagotchi.GameContent.Objects.Units
{
public class UnitLoader
{
public static List<string> GetTest() {
// MAC OS also prly Linux - var path = Path.Combine(Directory.GetCurrentDirectory(), "GameContent/Objects/Units/UnitDefines.csv");
//System.Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory());
//var path = "..\\..\\..\\GameContent\\Objects\\Units\\UnitDefines.csv";
List<string> listA = new List<string>();
return listA;
}
public static List <Unit> LoadUnitList ()
{
List<Unit> unitList = new List<Unit>();
Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory());
var path = "..\\..\\..\\Data\\BattleObjects\\UnitDefinitions.csv";
Console.WriteLine("path: {0} ", path);
// these let us resolve which column is which
int IdIndex = -1;
int NameIndex = -1;
int ClassIndex = -1;
int isUniqueIndex = -1;
int HealthIndex = -1;
int AttackIndex = -1;
int DefenseIndex = -1;
int SpeedIndex = -1;
int MovementIndex = -1;
int MovementTypeIndex = -1;
bool AreColumnIndexesSet = false;
using (var reader = new StreamReader(path))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
if (AreColumnIndexesSet == false)
{
//These strings MUST match /GameContent/Data/UnitDefines.CSV
// That file MUST have these in the first row.
for (int i = 0; i < values.Length; i++)
{
if (values[i].Trim() == "ID") { IdIndex = i; }
if (values[i].Trim() == "NAME") { NameIndex = i; }
if (values[i].Trim() == "CLASS") { ClassIndex = i; }
if (values[i].Trim() == "IS_UNIQUE") { isUniqueIndex = i; }
if (values[i].Trim() == "HEALTH") { HealthIndex = i; }
if (values[i].Trim() == "ATTACK") { AttackIndex = i; }
if (values[i].Trim() == "DEFENSE") { DefenseIndex = i; }
if (values[i].Trim() == "SPEED") { SpeedIndex = i; }
if (values[i].Trim() == "MOVEMENT") { MovementIndex = i; }
if (values[i].Trim() == "MOVEMENT_TYPE") { MovementTypeIndex = i; }
}
AreColumnIndexesSet = true;
}
else
{
Unit unit = new Unit();
unit.UnitID = int.Parse(values[IdIndex]);
unit.stats.classId = PlayerClass.GetClassFromShortHand(values[ClassIndex]);
// unit.isUnique = (values[isUniqueIndex].ToLower() == "true");
unit.name = unit.stats.Name = values[NameIndex];
unit.playerClassEnum = PlayerClass.GetClassFromShortHand(values[ClassIndex]);
TibzLog.Debug("loaded class - " + unit.playerClassEnum);
unit.stats.baseStats.MaxHealth = int.Parse(values[HealthIndex]);
unit.stats.baseStats.Attack = int.Parse(values[AttackIndex]);
unit.stats.baseStats.Defense = int.Parse(values[DefenseIndex]);
unit.stats.baseStats.Speed = int.Parse(values[SpeedIndex]);
unit.stats.baseStats.Movement = int.Parse(values[MovementIndex]);
unit.stats.baseStats.setMovementTypeFromFile(values[MovementTypeIndex]);
unitList.Add(unit);
}
}
}
return unitList;
}
}
}

View File

@ -11,7 +11,6 @@ using TibzGame.Core.Inputs;
using TibzGame.Core.ScreenManager; using TibzGame.Core.ScreenManager;
using Johnmagotchi.GameContent.Objects; using Johnmagotchi.GameContent.Objects;
using System.Text.Json; using System.Text.Json;
using Johnmagotchi.GameContent.Units;
using Johnmagotchi.GameContent.Objects.UI; using Johnmagotchi.GameContent.Objects.UI;
using Johnmagotchi.Core.tools; using Johnmagotchi.Core.tools;

View File

@ -4,7 +4,6 @@ using Johnmagotchi.GameContent.Objects;
using Johnmagotchi.GameContent.Objects.Maps; using Johnmagotchi.GameContent.Objects.Maps;
using Johnmagotchi.GameContent.Objects.Units; using Johnmagotchi.GameContent.Objects.Units;
using Johnmagotchi.GameContent.Screens.Menu.BattleMap; using Johnmagotchi.GameContent.Screens.Menu.BattleMap;
using Johnmagotchi.GameContent.Units;
using Johnmagotchi.Screen.BattleMapScreens; using Johnmagotchi.Screen.BattleMapScreens;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -252,7 +251,7 @@ namespace Johnmagotchi.GameContent.Screens.BattleMapScreens.BattleMapScreen
if (isConfirmed) if (isConfirmed)
{ {
// BattleLogic.RunBattle(selectedToMoveUnit,attackedUnit, selectedAttack, defenderAttack); // BattleLogic.RunBattle(selectedToMoveUnit,attackedUnit, selectedAttack, defenderAttack);
BattleLogic.RunBattle(ref selectedToMoveUnit, ref attackedUnit, null, null); BattleLogic.RunBattle(ref selectedToMoveUnit, ref attackedUnit);
screenManager.addScreen(new MapScreens.BattleMapScreen.BattleAnimationScreen()); screenManager.addScreen(new MapScreens.BattleMapScreen.BattleAnimationScreen());
} }

View File

@ -1,6 +1,5 @@
using Johnmagotchi.GameContent.Objects; using Johnmagotchi.GameContent.Objects;
using System.Collections.Generic; using System.Collections.Generic;
using Johnmagotchi.GameContent.Units;
using Johnmagotchi.Core.tools; using Johnmagotchi.Core.tools;
using Johnmagotchi.GameContent.Screens.Menu; using Johnmagotchi.GameContent.Screens.Menu;
using Johnmagotchi.GameContent.Screens.BattleMapScreens.MapEditor; using Johnmagotchi.GameContent.Screens.BattleMapScreens.MapEditor;
@ -8,8 +7,6 @@ using Microsoft.VisualBasic;
using static System.Net.Mime.MediaTypeNames; using static System.Net.Mime.MediaTypeNames;
using System.IO; using System.IO;
using System; using System;
using Johnmagotchi.GameContent.Objects.Units.Loadouts;
using Johnmagotchi.GameContent.Objects.Units.BattleObjects;
using Johnmagotchi.GameContent.Objects.Units; using Johnmagotchi.GameContent.Objects.Units;
namespace Johnmagotchi.Screen.BattleMapScreens namespace Johnmagotchi.Screen.BattleMapScreens
@ -34,7 +31,6 @@ namespace Johnmagotchi.Screen.BattleMapScreens
private EditorToolType CurrentTool; private EditorToolType CurrentTool;
private MapEditorInfoText InfoText; private MapEditorInfoText InfoText;
public List<Unit> AvailableNewUnits; public List<Unit> AvailableNewUnits;
public List<UnitLoadout> AvailableLoadouts;
private UnitFactionType UnitFaction; private UnitFactionType UnitFaction;