Create a gist now

Instantly share code, notes, and snippets.

@ScottLilly /Player.cs Secret
Last active Sep 23, 2017

What would you like to do?
Monster health progress bar
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Xml;
using Engine;
namespace Engine
{
public class Player : LivingCreature
{
public event EventHandler<MessageEventArgs> OnMessage;
// Active Players int
private int _gold;
private int _experiencePoints;
private Location _currentLocation;
public int PlayerBaseHP;
public int PlayerBaseMP;
private int _currentManaPoints;
private int _maxManaPoints;
public int _magicSkillExperience;
private int _shieldSkillEXP;
private int _attackSkillEXP;
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// // INT to Set Levels Required Experience (atm All share prob make seperate for Main Level and Skill levels)
//
// Level Caculator
// Multiplier allow for Easy Alteration with the required exp for each level and for each skill/level type
public int AttackSkillLevelMultiplier = 4;
public int ShieldSkillLevelMultiplier = 2;
public int MagicSkillLevelMultiplier = 3;
public int LevelMultiplier = 1; //<--- Not realy needed || if multply by one and can set base requirements,
//but may come in handy to add it aswell And can Mod exp without tuching Base exp
public int SkillLevel_000 = 100;
public int SkillLevel_001 = 210;
public int SkillLevel_002 = 330;
public int SkillLevel_003 = 460;
public int SkillLevel_004 = 600;
public int SkillLevel_005 = 750;
public int SkillLevel_006 = 910;
public int SkillLevel_007 = 1080;
public int SkillLevel_008 = 1260;
public int SkillLevel_009 = 1450;
public int SkillLevel_010 = 1650;
public int SkillLevel_011 = 1860;
public int SkillLevel_012 = 2080;
public int SkillLevel_013 = 2310;
public int SkillLevel_014 = 2550;
public int SkillLevel_015 = 2800;
public int SkillLevel_016 = 3060;
public int SkillLevel_017 = 3340;
public int SkillLevel_018 = 3620;
public int SkillLevel_019 = 3910;
public int SkillLevel_020 = 4210;
public int SkillLevel_MAX = 9999; // just To Have A ReturnValue Whilst Testing/finalising skill level
private static Monster _currentMonster;
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Caculates Main Level And Required Experience
public int Level
{
get
{
if (ExperiencePoints < SkillLevel_000) { return 0; }
if (ExperiencePoints < SkillLevel_001) { return 1; }
if (ExperiencePoints < SkillLevel_002) { return 2; }
if (ExperiencePoints < SkillLevel_003) { return 3; }
if (ExperiencePoints < SkillLevel_004) { return 4; }
if (ExperiencePoints < SkillLevel_005) { return 5; }
if (ExperiencePoints < SkillLevel_006) { return 6; }
if (ExperiencePoints < SkillLevel_007) { return 7; }
if (ExperiencePoints < SkillLevel_008) { return 8; }
if (ExperiencePoints < SkillLevel_009) { return 9; }
if (ExperiencePoints < SkillLevel_010) { return 10; }
if (ExperiencePoints < SkillLevel_011) { return 11; }
if (ExperiencePoints < SkillLevel_012) { return 12; }
if (ExperiencePoints < SkillLevel_013) { return 13; }
if (ExperiencePoints < SkillLevel_014) { return 14; }
if (ExperiencePoints < SkillLevel_015) { return 15; }
if (ExperiencePoints < SkillLevel_016) { return 16; }
if (ExperiencePoints < SkillLevel_017) { return 17; }
if (ExperiencePoints < SkillLevel_018) { return 18; }
if (ExperiencePoints < SkillLevel_019) { return 19; }
if (ExperiencePoints < SkillLevel_020) { return 20; }
return SkillLevel_MAX;
}
private set { OnPropertyChanged("Level"); }
}
// /////////////////////////////////////////////////////////////////////////////////////
//
// Caculates The Old Level required Experience ,
// Used as Refrence To get an aprox To next level percentage for Progrees Bar
public int OldlLevel
{
get
{
if (Level == 0) { return 0; }
if (Level == 1) { return SkillLevel_000; }
if (Level == 2) { return SkillLevel_001; }
if (Level == 3) { return SkillLevel_002; }
if (Level == 4) { return SkillLevel_003; }
if (Level == 5) { return SkillLevel_004; }
if (Level == 6) { return SkillLevel_005; }
if (Level == 7) { return SkillLevel_006; }
if (Level == 8) { return SkillLevel_007; }
if (Level == 9) { return SkillLevel_008; }
if (Level == 10) { return SkillLevel_009; }
if (Level == 11) { return SkillLevel_010; }
if (Level == 12) { return SkillLevel_011; }
if (Level == 13) { return SkillLevel_012; }
if (Level == 14) { return SkillLevel_013; }
if (Level == 15) { return SkillLevel_014; }
if (Level == 16) { return SkillLevel_015; }
if (Level == 17) { return SkillLevel_016; }
if (Level == 18) { return SkillLevel_017; }
if (Level == 19) { return SkillLevel_018; }
if (Level == 20) { return SkillLevel_019; }
if (Level == 21) { return SkillLevel_020; }
return SkillLevel_MAX;
}
set
{
OnPropertyChanged("OldLevel");
}
}
// // /////////////////////////////////////////////////////////////////////////////////////////
//
// Caculates The Next Level required Experience ,
// Used as Refrence To get an aprox To next level percentage for Progrees Bar
public int NextLevel
{
get
{
if (Level == 0) { return SkillLevel_000; }
if (Level == 1) { return SkillLevel_001; }
if (Level == 2) { return SkillLevel_002; }
if (Level == 3) { return SkillLevel_003; }
if (Level == 4) { return SkillLevel_004; }
if (Level == 5) { return SkillLevel_005; }
if (Level == 6) { return SkillLevel_006; }
if (Level == 7) { return SkillLevel_007; }
if (Level == 8) { return SkillLevel_008; }
if (Level == 9) { return SkillLevel_009; }
if (Level == 10) { return SkillLevel_010; }
if (Level == 11) { return SkillLevel_011; }
if (Level == 12) { return SkillLevel_012; }
if (Level == 13) { return SkillLevel_013; }
if (Level == 14) { return SkillLevel_014; }
if (Level == 15) { return SkillLevel_015; }
if (Level == 16) { return SkillLevel_016; }
if (Level == 17) { return SkillLevel_017; }
if (Level == 18) { return SkillLevel_018; }
if (Level == 19) { return SkillLevel_019; }
if (Level == 20) { return SkillLevel_020; }
if (Level == 21) { return SkillLevel_MAX; }
return SkillLevel_MAX;
}
set
{
OnPropertyChanged("NextLevel");
}
}
// ///////////////////////////////////////////////////////////////////////////////////////
// // ////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////////
//
// Caculates Main Shiekd Skill Level And Required Experience
public int ShieldSkill
{
get
{
if (ShieldSkillEXP < SkillLevel_000 * ShieldSkillLevelMultiplier) { return 0; }
if (ShieldSkillEXP < SkillLevel_001 * ShieldSkillLevelMultiplier) { return 1; }
if (ShieldSkillEXP < SkillLevel_002 * ShieldSkillLevelMultiplier) { return 2; }
if (ShieldSkillEXP < SkillLevel_003 * ShieldSkillLevelMultiplier) { return 3; }
if (ShieldSkillEXP < SkillLevel_004 * ShieldSkillLevelMultiplier) { return 4; }
if (ShieldSkillEXP < SkillLevel_005 * ShieldSkillLevelMultiplier) { return 5; }
if (ShieldSkillEXP < SkillLevel_006 * ShieldSkillLevelMultiplier) { return 6; }
if (ShieldSkillEXP < SkillLevel_007 * ShieldSkillLevelMultiplier) { return 7; }
if (ShieldSkillEXP < SkillLevel_008 * ShieldSkillLevelMultiplier) { return 8; }
if (ShieldSkillEXP < SkillLevel_009 * ShieldSkillLevelMultiplier) { return 9; }
if (ShieldSkillEXP < SkillLevel_010 * ShieldSkillLevelMultiplier) { return 10; }
if (ShieldSkillEXP < SkillLevel_011 * ShieldSkillLevelMultiplier) { return 11; }
if (ShieldSkillEXP < SkillLevel_012 * ShieldSkillLevelMultiplier) { return 12; }
if (ShieldSkillEXP < SkillLevel_013 * ShieldSkillLevelMultiplier) { return 13; }
if (ShieldSkillEXP < SkillLevel_014 * ShieldSkillLevelMultiplier) { return 14; }
if (ShieldSkillEXP < SkillLevel_015 * ShieldSkillLevelMultiplier) { return 15; }
if (ShieldSkillEXP < SkillLevel_016 * ShieldSkillLevelMultiplier) { return 16; }
if (ShieldSkillEXP < SkillLevel_017 * ShieldSkillLevelMultiplier) { return 17; }
if (ShieldSkillEXP < SkillLevel_018 * ShieldSkillLevelMultiplier) { return 18; }
if (ShieldSkillEXP < SkillLevel_019 * ShieldSkillLevelMultiplier) { return 19; }
if (ShieldSkillEXP < SkillLevel_020 * ShieldSkillLevelMultiplier) { return 20; }
return SkillLevel_MAX * ShieldSkillLevelMultiplier;
}
private set { OnPropertyChanged("ShieldSkill"); }
}
// /////////////////////////////////////////////////////////////////////////////////////
//
// Caculates The Old Level required Experience ,
// Used as Refrence To get an aprox To next level percentage for Progrees Bar
public int OldShieldSkillLevel
{
get
{
if (ShieldSkill == 0) { return 0; }
if (ShieldSkill == 1) { return SkillLevel_000 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 2) { return SkillLevel_001 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 3) { return SkillLevel_002 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 4) { return SkillLevel_003 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 5) { return SkillLevel_004 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 6) { return SkillLevel_005 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 7) { return SkillLevel_006 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 8) { return SkillLevel_007 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 9) { return SkillLevel_008 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 10) { return SkillLevel_009 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 11) { return SkillLevel_010 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 12) { return SkillLevel_011 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 13) { return SkillLevel_012 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 14) { return SkillLevel_013 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 15) { return SkillLevel_014 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 16) { return SkillLevel_015 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 17) { return SkillLevel_016 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 18) { return SkillLevel_017 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 19) { return SkillLevel_018 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 20) { return SkillLevel_019 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 21) { return SkillLevel_020 * ShieldSkillLevelMultiplier; }
return SkillLevel_MAX * ShieldSkillLevelMultiplier;
}
set
{
OnPropertyChanged("OldShieldSkillLevel");
}
}
// /////////////////////////////////////////////////////////////////////////////////////
//
// Caculates The Next Level required Experience ,
// Used as Refrence To get an aprox To next level percentage for Progrees Bar
public int NextShieldSkillLevel
{
get
{
if (ShieldSkill == 0) { return SkillLevel_000 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 1) { return SkillLevel_001 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 2) { return SkillLevel_002 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 3) { return SkillLevel_003 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 4) { return SkillLevel_004 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 5) { return SkillLevel_005 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 6) { return SkillLevel_006 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 7) { return SkillLevel_007 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 8) { return SkillLevel_008 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 9) { return SkillLevel_009 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 10) { return SkillLevel_010 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 11) { return SkillLevel_011 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 12) { return SkillLevel_012 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 13) { return SkillLevel_013 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 14) { return SkillLevel_014 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 15) { return SkillLevel_015 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 16) { return SkillLevel_016 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 17) { return SkillLevel_017 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 18) { return SkillLevel_018 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 19) { return SkillLevel_019 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 20) { return SkillLevel_020 * ShieldSkillLevelMultiplier; }
if (ShieldSkill == 21) { return SkillLevel_MAX * ShieldSkillLevelMultiplier; }
return SkillLevel_MAX * ShieldSkillLevelMultiplier;
}
set
{
OnPropertyChanged("NextShieldSkillLevel");
}
}
// // /////////////////////////////////////////////////////////////////////////////////////////
//
// Caculates The Attack Skill levels required Experience ,
//
public int AttackSkill
{
get
{
if (AttackSkillEXP < SkillLevel_000 * AttackSkillLevelMultiplier) { return 0; }
if (AttackSkillEXP < SkillLevel_001 * AttackSkillLevelMultiplier) { return 1; }
if (AttackSkillEXP < SkillLevel_002 * AttackSkillLevelMultiplier) { return 2; }
if (AttackSkillEXP < SkillLevel_003 * AttackSkillLevelMultiplier) { return 3; }
if (AttackSkillEXP < SkillLevel_004 * AttackSkillLevelMultiplier) { return 4; }
if (AttackSkillEXP < SkillLevel_005 * AttackSkillLevelMultiplier) { return 5; }
if (AttackSkillEXP < SkillLevel_006 * AttackSkillLevelMultiplier) { return 6; }
if (AttackSkillEXP < SkillLevel_007 * AttackSkillLevelMultiplier) { return 7; }
if (AttackSkillEXP < SkillLevel_008 * AttackSkillLevelMultiplier) { return 8; }
if (AttackSkillEXP < SkillLevel_009 * AttackSkillLevelMultiplier) { return 9; }
if (AttackSkillEXP < SkillLevel_010 * AttackSkillLevelMultiplier) { return 10; }
if (AttackSkillEXP < SkillLevel_011 * AttackSkillLevelMultiplier) { return 11; }
if (AttackSkillEXP < SkillLevel_012 * AttackSkillLevelMultiplier) { return 12; }
if (AttackSkillEXP < SkillLevel_013 * AttackSkillLevelMultiplier) { return 13; }
if (AttackSkillEXP < SkillLevel_014 * AttackSkillLevelMultiplier) { return 14; }
if (AttackSkillEXP < SkillLevel_015 * AttackSkillLevelMultiplier) { return 15; }
if (AttackSkillEXP < SkillLevel_016 * AttackSkillLevelMultiplier) { return 16; }
if (AttackSkillEXP < SkillLevel_017 * AttackSkillLevelMultiplier) { return 17; }
if (AttackSkillEXP < SkillLevel_018 * AttackSkillLevelMultiplier) { return 18; }
if (AttackSkillEXP < SkillLevel_019 * AttackSkillLevelMultiplier) { return 19; }
if (AttackSkillEXP < SkillLevel_020 * AttackSkillLevelMultiplier) { return 20; }
return SkillLevel_MAX;
}
private set { OnPropertyChanged("AttackSkill"); }
}
// /////////////////////////////////////////////////////////////////////////////////////
//
// Caculates The Old Level required Experience ,
// Used as Refrence To get an aprox To next level percentage for Progrees Bar
public int OldAttackSkillLevel
{
get
{
if (AttackSkill == 0) { return 0; }
if (AttackSkill == 1) { return SkillLevel_000 * AttackSkillLevelMultiplier; }
if (AttackSkill == 2) { return SkillLevel_001 * AttackSkillLevelMultiplier; }
if (AttackSkill == 3) { return SkillLevel_002 * AttackSkillLevelMultiplier; }
if (AttackSkill == 4) { return SkillLevel_003 * AttackSkillLevelMultiplier; }
if (AttackSkill == 5) { return SkillLevel_004 * AttackSkillLevelMultiplier; }
if (AttackSkill == 6) { return SkillLevel_005 * AttackSkillLevelMultiplier; }
if (AttackSkill == 7) { return SkillLevel_006 * AttackSkillLevelMultiplier; }
if (AttackSkill == 8) { return SkillLevel_007 * AttackSkillLevelMultiplier; }
if (AttackSkill == 9) { return SkillLevel_008 * AttackSkillLevelMultiplier; }
if (AttackSkill == 10) { return SkillLevel_009 * AttackSkillLevelMultiplier; }
if (AttackSkill == 11) { return SkillLevel_010 * AttackSkillLevelMultiplier; }
if (AttackSkill == 12) { return SkillLevel_011 * AttackSkillLevelMultiplier; }
if (AttackSkill == 13) { return SkillLevel_012 * AttackSkillLevelMultiplier; }
if (AttackSkill == 14) { return SkillLevel_013 * AttackSkillLevelMultiplier; }
if (AttackSkill == 15) { return SkillLevel_014 * AttackSkillLevelMultiplier; }
if (AttackSkill == 16) { return SkillLevel_015 * AttackSkillLevelMultiplier; }
if (AttackSkill == 17) { return SkillLevel_016 * AttackSkillLevelMultiplier; }
if (AttackSkill == 18) { return SkillLevel_017 * AttackSkillLevelMultiplier; }
if (AttackSkill == 19) { return SkillLevel_018 * AttackSkillLevelMultiplier; }
if (AttackSkill == 20) { return SkillLevel_019 * AttackSkillLevelMultiplier; }
if (AttackSkill == 21) { return SkillLevel_020 * AttackSkillLevelMultiplier; }
return SkillLevel_MAX * AttackSkillLevelMultiplier;
}
set
{
OnPropertyChanged("OldAttackSkillLevel");
}
}
// /////////////////////////////////////////////////////////////////////////////////////
//
// Caculates The Next Level required Experience ,
// Used as Refrence To get an aprox To next level percentage for Progrees Bar
public int NextAttackSkillLevel
{
get
{
if (AttackSkill == 0) { return SkillLevel_000 * AttackSkillLevelMultiplier; }
if (AttackSkill == 1) { return SkillLevel_001 * AttackSkillLevelMultiplier; }
if (AttackSkill == 2) { return SkillLevel_002 * AttackSkillLevelMultiplier; }
if (AttackSkill == 3) { return SkillLevel_003 * AttackSkillLevelMultiplier; }
if (AttackSkill == 4) { return SkillLevel_004 * AttackSkillLevelMultiplier; }
if (AttackSkill == 5) { return SkillLevel_005 * AttackSkillLevelMultiplier; }
if (AttackSkill == 6) { return SkillLevel_006 * AttackSkillLevelMultiplier; }
if (AttackSkill == 7) { return SkillLevel_007 * AttackSkillLevelMultiplier; }
if (AttackSkill == 8) { return SkillLevel_008 * AttackSkillLevelMultiplier; }
if (AttackSkill == 9) { return SkillLevel_009 * AttackSkillLevelMultiplier; }
if (AttackSkill == 10) { return SkillLevel_010 * AttackSkillLevelMultiplier; }
if (AttackSkill == 11) { return SkillLevel_011 * AttackSkillLevelMultiplier; }
if (AttackSkill == 12) { return SkillLevel_012 * AttackSkillLevelMultiplier; }
if (AttackSkill == 13) { return SkillLevel_013 * AttackSkillLevelMultiplier; }
if (AttackSkill == 14) { return SkillLevel_014 * AttackSkillLevelMultiplier; }
if (AttackSkill == 15) { return SkillLevel_015 * AttackSkillLevelMultiplier; }
if (AttackSkill == 16) { return SkillLevel_016 * AttackSkillLevelMultiplier; }
if (AttackSkill == 17) { return SkillLevel_017 * AttackSkillLevelMultiplier; }
if (AttackSkill == 18) { return SkillLevel_018 * AttackSkillLevelMultiplier; }
if (AttackSkill == 19) { return SkillLevel_019 * AttackSkillLevelMultiplier; }
if (AttackSkill == 20) { return SkillLevel_020 * AttackSkillLevelMultiplier; }
if (AttackSkill == 21) { return SkillLevel_MAX * AttackSkillLevelMultiplier; }
return SkillLevel_MAX;
}
set
{
OnPropertyChanged("NextAttackSkillLevel");
}
}
// // ////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////////
//
// Caculates Magic Skill Level And Required Experience
public int MagicSkill
{
get
{
if (MagicSKillExperience < SkillLevel_000 * MagicSkillLevelMultiplier) { return 0; }
if (MagicSKillExperience < SkillLevel_001 * MagicSkillLevelMultiplier) { return 1; }
if (MagicSKillExperience < SkillLevel_002 * MagicSkillLevelMultiplier) { return 2; }
if (MagicSKillExperience < SkillLevel_003 * MagicSkillLevelMultiplier) { return 3; }
if (MagicSKillExperience < SkillLevel_004 * MagicSkillLevelMultiplier) { return 4; }
if (MagicSKillExperience < SkillLevel_005 * MagicSkillLevelMultiplier) { return 5; }
if (MagicSKillExperience < SkillLevel_006 * MagicSkillLevelMultiplier) { return 6; }
if (MagicSKillExperience < SkillLevel_007 * MagicSkillLevelMultiplier) { return 7; }
if (MagicSKillExperience < SkillLevel_008 * MagicSkillLevelMultiplier) { return 8; }
if (MagicSKillExperience < SkillLevel_009 * MagicSkillLevelMultiplier) { return 9; }
if (MagicSKillExperience < SkillLevel_010 * MagicSkillLevelMultiplier) { return 10; }
if (MagicSKillExperience < SkillLevel_011 * MagicSkillLevelMultiplier) { return 11; }
if (MagicSKillExperience < SkillLevel_012 * MagicSkillLevelMultiplier) { return 12; }
if (MagicSKillExperience < SkillLevel_013 * MagicSkillLevelMultiplier) { return 13; }
if (MagicSKillExperience < SkillLevel_014 * MagicSkillLevelMultiplier) { return 14; }
if (MagicSKillExperience < SkillLevel_015 * MagicSkillLevelMultiplier) { return 15; }
if (MagicSKillExperience < SkillLevel_016 * MagicSkillLevelMultiplier) { return 16; }
if (MagicSKillExperience < SkillLevel_017 * MagicSkillLevelMultiplier) { return 17; }
if (MagicSKillExperience < SkillLevel_018 * MagicSkillLevelMultiplier) { return 18; }
if (MagicSKillExperience < SkillLevel_019 * MagicSkillLevelMultiplier) { return 19; }
if (MagicSKillExperience < SkillLevel_020 * MagicSkillLevelMultiplier) { return 20; }
return SkillLevel_MAX * MagicSkillLevelMultiplier;
}
private set { OnPropertyChanged("MagicSkill"); }
}
// ///////////////////////////////////////////////////////////////////////////////////////////
// Caculates The Old Magic skill Level required Experience ,
// Used as Refrence To get an aprox To next level percentage for Progrees Bar
public int OldMagicSkillLevel
{
get
{
if (MagicSkill == 0) { return 0; }
if (MagicSkill == 1) { return SkillLevel_000 * MagicSkillLevelMultiplier; }
if (MagicSkill == 2) { return SkillLevel_001 * MagicSkillLevelMultiplier; }
if (MagicSkill == 3) { return SkillLevel_002 * MagicSkillLevelMultiplier; }
if (MagicSkill == 4) { return SkillLevel_003 * MagicSkillLevelMultiplier; }
if (MagicSkill == 5) { return SkillLevel_004 * MagicSkillLevelMultiplier; }
if (MagicSkill == 6) { return SkillLevel_005 * MagicSkillLevelMultiplier; }
if (MagicSkill == 7) { return SkillLevel_006 * MagicSkillLevelMultiplier; }
if (MagicSkill == 8) { return SkillLevel_007 * MagicSkillLevelMultiplier; }
if (MagicSkill == 9) { return SkillLevel_008 * MagicSkillLevelMultiplier; }
if (MagicSkill == 10) { return SkillLevel_009 * MagicSkillLevelMultiplier; }
if (MagicSkill == 11) { return SkillLevel_010 * MagicSkillLevelMultiplier; }
if (MagicSkill == 12) { return SkillLevel_011 * MagicSkillLevelMultiplier; }
if (MagicSkill == 13) { return SkillLevel_012 * MagicSkillLevelMultiplier; }
if (MagicSkill == 14) { return SkillLevel_013 * MagicSkillLevelMultiplier; }
if (MagicSkill == 15) { return SkillLevel_014 * MagicSkillLevelMultiplier; }
if (MagicSkill == 16) { return SkillLevel_015 * MagicSkillLevelMultiplier; }
if (MagicSkill == 17) { return SkillLevel_016 * MagicSkillLevelMultiplier; }
if (MagicSkill == 18) { return SkillLevel_017 * MagicSkillLevelMultiplier; }
if (MagicSkill == 19) { return SkillLevel_018 * MagicSkillLevelMultiplier; }
if (MagicSkill == 20) { return SkillLevel_019 * MagicSkillLevelMultiplier; }
if (MagicSkill == 21) { return SkillLevel_020 * MagicSkillLevelMultiplier; }
return SkillLevel_MAX * MagicSkillLevelMultiplier;
}
set
{
OnPropertyChanged("OldMagicSkillLevel");
}
}
// /////////////////////////////////////////////////////////////////////////////////////
//
// Caculates The Next Magic Skill Level required Experience ,
// Used as Refrence To get an aprox To next level percentage for Progrees Bar
public int NextMagicSkillLevel
{
get
{
if (MagicSkill == 0) { return SkillLevel_000 * MagicSkillLevelMultiplier; }
if (MagicSkill == 1) { return SkillLevel_001 * MagicSkillLevelMultiplier; }
if (MagicSkill == 2) { return SkillLevel_002 * MagicSkillLevelMultiplier; }
if (MagicSkill == 3) { return SkillLevel_003 * MagicSkillLevelMultiplier; }
if (MagicSkill == 4) { return SkillLevel_004 * MagicSkillLevelMultiplier; }
if (MagicSkill == 5) { return SkillLevel_005 * MagicSkillLevelMultiplier; }
if (MagicSkill == 6) { return SkillLevel_006 * MagicSkillLevelMultiplier; }
if (MagicSkill == 7) { return SkillLevel_007 * MagicSkillLevelMultiplier; }
if (MagicSkill == 8) { return SkillLevel_008 * MagicSkillLevelMultiplier; }
if (MagicSkill == 9) { return SkillLevel_009 * MagicSkillLevelMultiplier; }
if (MagicSkill == 10) { return SkillLevel_010 * MagicSkillLevelMultiplier; }
if (MagicSkill == 11) { return SkillLevel_011 * MagicSkillLevelMultiplier; }
if (MagicSkill == 12) { return SkillLevel_012 * MagicSkillLevelMultiplier; }
if (MagicSkill == 13) { return SkillLevel_013 * MagicSkillLevelMultiplier; }
if (MagicSkill == 14) { return SkillLevel_014 * MagicSkillLevelMultiplier; }
if (MagicSkill == 15) { return SkillLevel_015 * MagicSkillLevelMultiplier; }
if (MagicSkill == 16) { return SkillLevel_016 * MagicSkillLevelMultiplier; }
if (MagicSkill == 17) { return SkillLevel_017 * MagicSkillLevelMultiplier; }
if (MagicSkill == 18) { return SkillLevel_018 * MagicSkillLevelMultiplier; }
if (MagicSkill == 19) { return SkillLevel_019 * MagicSkillLevelMultiplier; }
if (MagicSkill == 20) { return SkillLevel_020 * MagicSkillLevelMultiplier; }
if (MagicSkill == 21) { return SkillLevel_MAX * MagicSkillLevelMultiplier; }
return SkillLevel_MAX * MagicSkillLevelMultiplier;
}
set
{
OnPropertyChanged("NextMagicSkillLevel");
}
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Current Player Stats/Attributes With OnPropertyChange
// Battle related
public int AttackSkillEXP
{
get { return _attackSkillEXP; }
set
{
_attackSkillEXP = value;
OnPropertyChanged("AttackSkillEXP");
}
}
public int ShieldSkillEXP
{
get { return _shieldSkillEXP; }
set
{
_shieldSkillEXP = value;
OnPropertyChanged("ShieldSkillEXP");
}
}
public int MagicSKillExperience
{
get { return _magicSkillExperience; }
set
{
_magicSkillExperience = value;
OnPropertyChanged("MagicSkillEperience");
}
}
public int MaxManaPoints
{
get { return _maxManaPoints; }
set
{
_maxManaPoints = value;
OnPropertyChanged("MaxManaPoints");
}
}
public int CurrentManaPoints
{
get { return _currentManaPoints; }
set
{
_currentManaPoints = value;
OnPropertyChanged("CurrentManaPoints");
}
}
public int Gold
{
get { return _gold; }
set
{
_gold = value;
OnPropertyChanged("Gold");
}
}
public int ExperiencePoints
{
get { return _experiencePoints; }
private set
{
_experiencePoints = value;
OnPropertyChanged("ExperiencePoints");
}
}
public Location CurrentLocation
{
get { return _currentLocation; }
set
{
_currentLocation = value;
OnPropertyChanged("CurrentLocation");
}
}
public Weapon CurrentWeapon { get; set; }
public Spell CurrentSpell { get; set; }
public HealingPotion CurrentPotion { get ; set; }
public BindingList<InventoryItem> Inventory { get; set; }
public List<Weapon> Weapons
{
get { return Inventory.Where(x => x.Details is Weapon).Select(x => x.Details as Weapon).ToList(); }
}
public List<HealingPotion> Potions
{
get { return Inventory.Where(x => x.Details is HealingPotion).Select(x => x.Details as HealingPotion).ToList(); }
}
public List<Spell> Spells
{
get { return Inventory.Where(x => x.Details is Spell).Select(x => x.Details as Spell).ToList(); }
}
public BindingList<PlayerQuest> Quests { get; set; }
public List<int> LocationsVisited { get; set; }
// ////////////////////////////////////////////////
// /////////////////////
//ActiveMonster
public Monster CurrentMonster
{
get { return _currentMonster; }
set
{
_currentMonster = value;
OnPropertyChanged("CurrentMonster");
}
}
// ////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////
// Start Set Active Player Details
private Player( int currentHitPoints, int maximumHitPoints, int gold, int experiencePoints, int playerBaseHP, int playerBaseMP, int currentManaPoints, int maxManaPoints, int magicSkillExperience, int shieldSkillEXP, int attackSkillEXP ) : base(currentHitPoints, maximumHitPoints)
{
Gold = gold;
ExperiencePoints = experiencePoints;
PlayerBaseHP = playerBaseHP;
PlayerBaseMP = playerBaseMP;
CurrentManaPoints = currentManaPoints;
MaxManaPoints = maxManaPoints;
MagicSKillExperience = magicSkillExperience;
ShieldSkillEXP = shieldSkillEXP;
AttackSkillEXP = attackSkillEXP;
// NextMagicSkillLevel = nextMagicSkillLevel;
Inventory = new BindingList<InventoryItem>();
Quests = new BindingList<PlayerQuest>();
LocationsVisited = new List<int>();
}
//
// End Of Set Active Player Details
// ////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////
// Player Creattion
// /////////////////////
// Start Create Defult Player
public static Player CreateDefaultPlayer()
{
Player player = new Player( 50, 50, 30, 0, 50, 50, 50, 50, 0, 0, 0);
player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1));
player.CurrentLocation = World.LocationByID(World.LOCATION_ID_HOME);
return player;
}
//
// End Create Default Player
// /////////////////////////////
// //////////////////////////////////////////////////////////////////
// /////////////////////////////////
// Create/Load Player From Saved SQL Data
//
public static Player CreatePlayerFromDatabase( int currentHitPoints, int maximumHitPoints, int gold, int experiencePoints, int currentLocationID, int playerBaseHP, int playerBaseMP, int currentManaPoints, int maxManaPoints, int magicSkillExperience, int shieldSkillEXP, int attackSkillEXP )
{
Player player = new Player( currentHitPoints, maximumHitPoints, gold, experiencePoints, playerBaseHP, playerBaseMP, currentManaPoints, maxManaPoints, magicSkillExperience, shieldSkillEXP, attackSkillEXP);
return player;
}
//
// End Of Craete/Load Player from Saved SQL Data
// //////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////
// Start Of Player Navigation
//
public void MoveTo(Location location)
{
if (PlayerDoesNotHaveTheRequiredItemToEnter(location))
{
RaiseMessage("You must have a " + location.ItemRequiredToEnter.Name + " to enter this location.");
return;
}
// The player can enter this location
CurrentLocation = location;
if (!LocationsVisited.Contains(CurrentLocation.ID))
{
LocationsVisited.Add(CurrentLocation.ID);
}
// CompletelyHeal();
if (location.HasAQuest)
{
if (PlayerDoesNotHaveThisQuest(location.QuestAvailableHere))
{
GiveQuestToPlayer(location.QuestAvailableHere);
}
else
{
if (PlayerHasNotCompleted(location.QuestAvailableHere) &&
PlayerHasAllQuestCompletionItemsFor(location.QuestAvailableHere))
{
GivePlayerQuestRewards(location.QuestAvailableHere);
}
}
}
SetTheCurrentMonsterForTheCurrentLocation(location);
}
public void MoveNorth()
{
if (CurrentLocation.LocationToNorth != null)
{
MoveTo(CurrentLocation.LocationToNorth);
}
}
public void MoveEast()
{
if (CurrentLocation.LocationToEast != null)
{
MoveTo(CurrentLocation.LocationToEast);
}
}
public void MoveSouth()
{
if (CurrentLocation.LocationToSouth != null)
{
MoveTo(CurrentLocation.LocationToSouth);
}
}
public void MoveWest()
{
if (CurrentLocation.LocationToWest != null)
{
MoveTo(CurrentLocation.LocationToWest);
}
}
// End Player Navigation
// ///////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////
// Start of Battle System
// ///////////////////////////////////////////////
// Start of Monster Attack Battle System
private void LetTheMonsterAttack()
{
int PlayersTotalDefense = ShieldSkill;
int PlayerBattleDefense = RandomNumberGenerator.NumberBetween(0, PlayersTotalDefense);
int MonsterBattleAttk = RandomNumberGenerator.NumberBetween(0, CurrentMonster.MaximumDamage);
int damageToPlayer = (MonsterBattleAttk - PlayerBattleDefense);
if (damageToPlayer < 0)
{
damageToPlayer = 0;
}
RaiseMessage("");
RaiseMessage("The " + CurrentMonster.Name + " did " + damageToPlayer + " points of damage."); // Main Keep
RaiseMessage("Player total Battle Defense: " + PlayersTotalDefense + "Player Battle Defense : " + PlayerBattleDefense + " Monster Attack " + MonsterBattleAttk + " Damage to player " + damageToPlayer); // Test Delete after testing
CurrentHitPoints -= damageToPlayer;
if (damageToPlayer > 0)
{
AddShieldSkillExp(damageToPlayer);
}
if (IsDead)
{
RaiseMessage("");
RaiseMessage("The " + CurrentMonster.Name + " killed you.");
MoveHome();
//CompletelyHeal();
}
}
//
// End of Monster Attack Battle System
// /////////////////////////////////////////////////////////
// Start Of Healing Battle Function
//
private void CompletelyHeal()
{
CurrentHitPoints = MaximumHitPoints;
CurrentManaPoints = MaxManaPoints;
}
private void MagicHealPlayer(int HealAmount, int ManaCost)
{
CurrentHitPoints = Math.Min(CurrentHitPoints + HealAmount, MaximumHitPoints);
UseManaPoints(ManaCost);
}
private void PotionRestorePlayer(int hitPointsToHeal, int ManaPointsToRestore)
{
CurrentHitPoints = Math.Min(CurrentHitPoints + hitPointsToHeal, MaximumHitPoints);
CurrentManaPoints = Math.Min(CurrentManaPoints + ManaPointsToRestore, MaxManaPoints);
}
// //////////////////////////////////////////////////////////////////////
// Replaced With PotionRestorePlayer Void
// private void HealPlayer(int hitPointsToHeal, int ManaPointsToRestore)
// {
// CurrentHitPoints = Math.Min(CurrentHitPoints + hitPointsToHeal, MaximumHitPoints);
//
// }
// private void RestorePlayerMana(int ManaPointsToRestore)
// {
// CurrentManaPoints = Math.Min(CurrentManaPoints + ManaPointsToRestore, MaxManaPoints);
// }
//
// ///////////////////////////////////////////
//
// End of Healing Functions
// //////////////////////////////////////////////////////////
// Start Mana Consuption Function
//
private void UseManaPoints(int ManaCost)
{
CurrentManaPoints = Math.Min(CurrentManaPoints - ManaCost, MaxManaPoints);
}
// End of Mana Consuption
// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Weapon Battle
public void UseWeapon(Weapon weapon)
{
int PlayersTotalBattleAttack = AttackSkill;
int MaxBattleAttack = (weapon.MaximumDamage + PlayersTotalBattleAttack);
int damage = RandomNumberGenerator.NumberBetween(weapon.MinimumDamage, MaxBattleAttack);
if (damage < 0 )
{
damage = 0;
}
if (damage == 0)
{
RaiseMessage("");
RaiseMessage("You missed the " + CurrentMonster.Name);
RaiseMessage("Player Total Battle Attack: " + PlayersTotalBattleAttack + "Player Battle Attack: " + MaxBattleAttack + " Damage: " + damage); // Test Delete after testing
}
else
{
CurrentMonster.CurrentHitPoints -= damage;
AddAttackSkillExp(damage);
RaiseMessage("");
RaiseMessage("You hit the " + CurrentMonster.Name + " for " + damage + " points.");
RaiseMessage("Player Total Battle Attack: " + PlayersTotalBattleAttack + "Player Battle Attack: " + MaxBattleAttack + " Damage: " + damage); // Test Delete after testing
}
if (CurrentMonster.IsDead)
{
LootTheCurrentMonster();
MoveTo(CurrentLocation); // "Move" to the current location, to refresh the current monster
}
else
{
LetTheMonsterAttack();
}
}
private void LootTheCurrentMonster()
{
RaiseMessage("");
RaiseMessage("You defeated the " + CurrentMonster.Name);
RaiseMessage("You receive " + CurrentMonster.RewardExperiencePoints + " experience points");
RaiseMessage("You receive " + CurrentMonster.RewardGold + " gold");
AddExperiencePoints(CurrentMonster.RewardExperiencePoints);
Gold += CurrentMonster.RewardGold;
// Give monster's loot items to the player
foreach (InventoryItem inventoryItem in CurrentMonster.LootItems)
{
AddItemToInventory(inventoryItem.Details);
RaiseMessage(string.Format("You loot {0} {1}", inventoryItem.Quantity, inventoryItem.Description));
}
RaiseMessage("");
}
public void UsePotion(HealingPotion potion)
{
RaiseMessage("You drink a " + potion.Name);
PotionRestorePlayer(potion.AmountToHeal, potion.RestoreManaAmount);
// RestorePlayerMana(potion.RestoreManaAmount);
RemoveItemFromInventory(potion);
// The player used their turn to drink the potion, so let the monster attack now
LetTheMonsterAttack();
}
public void UseSpells(Spell spell)
{
// RaiseMessage("You used "+ spell.ManaCost + "Casting Magic Spell " + spell.Name);
if (spell.HealAmount < 0)
{
spell.HealAmount = 0;
}
if (spell.HealAmount > 0 )
{
MagicHealPlayer(spell.HealAmount, spell.ManaCost);
}
if (spell.AttackAmount < 0)
{
spell.AttackAmount = 0;
}
if (spell.AttackAmount > 0)
{
int MaxBattleMagicDamage = (spell.AttackAmount + MagicSkill);
int magicdamage = RandomNumberGenerator.NumberBetween( spell.AttackAmount, MaxBattleMagicDamage);
CurrentMonster.CurrentHitPoints -= magicdamage ;
RaiseMessage("");
RaiseMessage("You hit the " + CurrentMonster.Name + " for " + spell.AttackAmount + " points."); // Keep
RaiseMessage("Player Battle Magic: " + MaxBattleMagicDamage + " Magic Damage " + magicdamage); // Test Delete after testing
AddMagicSkillExp(spell.AttackAmount);
UseManaPoints(spell.ManaCost);
}
if (CurrentMonster.IsDead)
{
LootTheCurrentMonster();
MoveTo(CurrentLocation); // "Move" to the current location, to refresh the current monster
}
LetTheMonsterAttack();
}
// End of Battle System
// ///////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////
// Start Add And Remove Inventory Items
public void AddItemToInventory(Item itemToAdd, int quantity = 1)
{
InventoryItem existingItemInInventory = Inventory.SingleOrDefault(ii => ii.Details.ID == itemToAdd.ID);
if (existingItemInInventory == null)
{
Inventory.Add(new InventoryItem(itemToAdd, quantity));
}
else
{
existingItemInInventory.Quantity += quantity;
}
RaiseInventoryChangedEvent(itemToAdd);
}
public void RemoveItemFromInventory(Item itemToRemove, int quantity = 1)
{
InventoryItem item = Inventory.SingleOrDefault(ii => ii.Details.ID == itemToRemove.ID && ii.Quantity >= quantity);
if (item != null)
{
item.Quantity -= quantity;
if (item.Quantity == 0)
{
Inventory.Remove(item);
}
RaiseInventoryChangedEvent(itemToRemove);
}
}
// End of Add And Remove Inventory Items
// ///////////////////////////////////////////////
private bool HasRequiredItemToEnterThisLocation(Location location)
{
if (location.DoesNotHaveAnItemRequiredToEnter)
{
return true;
}
// See if the player has the required item in their inventory
return Inventory.Any(ii => ii.Details.ID == location.ItemRequiredToEnter.ID);
}
private void SetTheCurrentMonsterForTheCurrentLocation(Location location)
{
// Populate the current monster with this location's monster (or null, if there is no monster here)
CurrentMonster = location.NewInstanceOfMonsterLivingHere();
if (CurrentMonster != null)
{
RaiseMessage("You see a " + CurrentMonster.Name);
}
}
private bool PlayerDoesNotHaveTheRequiredItemToEnter(Location location)
{
return !HasRequiredItemToEnterThisLocation(location);
}
private bool PlayerDoesNotHaveThisQuest(Quest quest)
{
return Quests.All(pq => pq.Details.ID != quest.ID);
}
private bool PlayerHasNotCompleted(Quest quest)
{
return Quests.Any(pq => pq.Details.ID == quest.ID && !pq.IsCompleted);
}
private void GiveQuestToPlayer(Quest quest)
{
RaiseMessage("You receive the " + quest.Name + " quest.");
RaiseMessage(quest.Description);
RaiseMessage("To complete it, return with:");
foreach (QuestCompletionItem qci in quest.QuestCompletionItems)
{
RaiseMessage(string.Format("{0} {1}", qci.Quantity,
qci.Quantity == 1 ? qci.Details.Name : qci.Details.NamePlural));
}
// RaiseMessage("");
Quests.Add(new PlayerQuest(quest));
}
private bool PlayerHasAllQuestCompletionItemsFor(Quest quest)
{
// See if the player has all the items needed to complete the quest here
foreach (QuestCompletionItem qci in quest.QuestCompletionItems)
{
// Check each item in the player's inventory, to see if they have it, and enough of it
if (!Inventory.Any(ii => ii.Details.ID == qci.Details.ID && ii.Quantity >= qci.Quantity))
{
return false;
}
}
// If we got here, then the player must have all the required items, and enough of them, to complete the quest.
return true;
}
private void RemoveQuestCompletionItems(Quest quest)
{
foreach (QuestCompletionItem qci in quest.QuestCompletionItems)
{
InventoryItem item = Inventory.SingleOrDefault(ii => ii.Details.ID == qci.Details.ID);
if (item != null)
{
RemoveItemFromInventory(item.Details, qci.Quantity);
}
}
}
// ///////////////////////////////////////////////////////////
// //////////////////////////////
// Start of Add To Experience Equations
private void AddAttackSkillExp(int AttackSkillEXPToAdd)
{
AttackSkillEXP += AttackSkillEXPToAdd;
}
private void AddShieldSkillExp(int ShieldSkillEXPToAdd)
{
ShieldSkillEXP += ShieldSkillEXPToAdd;
}
private void AddMagicSkillExp(int magicSKillExperienceToAdd)
{
MagicSKillExperience+= magicSKillExperienceToAdd;
}
private void AddExperiencePoints(int experiencePointsToAdd)
{
ExperiencePoints += experiencePointsToAdd;
MaximumHitPoints = (PlayerBaseHP + Level * 5);
MaxManaPoints = (PlayerBaseMP + Level * 5);
}
// End Of Add To Experience Functions
// ///////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////
//Start of Quest Completion Functions
private void GivePlayerQuestRewards(Quest quest)
{
// RaiseMessage("");
RaiseMessage("You complete the '" + quest.Name + "' quest.");
RaiseMessage("You receive: ");
RaiseMessage(quest.RewardExperiencePoints + " experience points");
RaiseMessage(quest.RewardGold + " gold");
RaiseMessage(quest.RewardItem.Name, true);
AddExperiencePoints(quest.RewardExperiencePoints);
Gold += quest.RewardGold;
RemoveQuestCompletionItems(quest);
AddItemToInventory(quest.RewardItem);
MarkPlayerQuestCompleted(quest);
}
private void MarkPlayerQuestCompleted(Quest quest)
{
PlayerQuest playerQuest = Quests.SingleOrDefault(pq => pq.Details.ID == quest.ID);
if (playerQuest != null)
{
playerQuest.IsCompleted = true;
}
}
// End of Quest Completion Functions
// ///////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////
// Start Teleport Player Home
//
private void MoveHome()
{
MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
CompletelyHeal();
}
// End of Teleport Player Home
// ////////////////////////////////////////////////////////
private void RaiseInventoryChangedEvent(Item item)
{
if (item is Weapon)
{
OnPropertyChanged("Weapons");
}
if (item is HealingPotion)
{
OnPropertyChanged("Potions");
}
if (item is Spell)
{
OnPropertyChanged("Spells");
}
}
private void RaiseMessage(string message, bool addExtraNewLine = false)
{
if (OnMessage != null)
{
OnMessage(this, new MessageEventArgs(message, addExtraNewLine));
}
}
// /////////////////////////////////////////////////////////////////////////
// Start of XML Function Comands (Methods)
private void CreateNewChildXmlNode(XmlDocument document, XmlNode parentNode, string elementName, object value)
{
XmlNode node = document.CreateElement(elementName);
node.AppendChild(document.CreateTextNode(value.ToString()));
parentNode.AppendChild(node);
}
private void AddXmlAttributeToNode(XmlDocument document, XmlNode node, string attributeName, object value)
{
XmlAttribute attribute = document.CreateAttribute(attributeName);
attribute.Value = value.ToString();
node.Attributes.Append(attribute);
}
// End of XML Function Comands (Methods)
// ///////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////
// Start of XML Writer
// //////////////////////////////
// Start of XML Writer, Save player File
//
public string ToXmlString()
{
XmlDocument playerData = new XmlDocument();
// Create the top-level XML node
XmlNode player = playerData.CreateElement("Player");
playerData.AppendChild(player);
// Create the "Stats" child node to hold the other player statistics nodes
XmlNode stats = playerData.CreateElement("Stats");
player.AppendChild(stats);
// Create the child nodes for the "Stats" node
CreateNewChildXmlNode(playerData, stats, "CurrentHitPoints", CurrentHitPoints);
CreateNewChildXmlNode(playerData, stats, "MaximumHitPoints", MaximumHitPoints);
CreateNewChildXmlNode(playerData, stats, "Gold", Gold);
CreateNewChildXmlNode(playerData, stats, "ExperiencePoints", ExperiencePoints);
CreateNewChildXmlNode(playerData, stats, "CurrentLocation", CurrentLocation.ID);
CreateNewChildXmlNode(playerData, stats, "PlayerBaseHP", PlayerBaseHP);
CreateNewChildXmlNode(playerData, stats, "PlayerBaseMP", PlayerBaseMP);
CreateNewChildXmlNode(playerData, stats, "CurrentManaPoints", CurrentManaPoints);
CreateNewChildXmlNode(playerData, stats, "MaxManaPoints", MaxManaPoints);
CreateNewChildXmlNode(playerData, stats, "MagicSKillExperience", MagicSKillExperience);
CreateNewChildXmlNode(playerData, stats, "ShieldSkillEXP", ShieldSkillEXP);
CreateNewChildXmlNode(playerData, stats, "AttackSkillEXP", AttackSkillEXP);
if (CurrentWeapon != null)
{
CreateNewChildXmlNode(playerData, stats, "CurrentWeapon", CurrentWeapon.ID);
}
if (CurrentSpell != null)
{
CreateNewChildXmlNode(playerData, stats, "CurrentSpell", CurrentSpell.ID);
}
// Create the "LocationsVisited" child node to hold each LocationVisited node
XmlNode locationsVisited = playerData.CreateElement("LocationsVisited");
player.AppendChild(locationsVisited);
// Create an "LocationVisited" node for each item in the player's inventory
foreach (int locationID in LocationsVisited)
{
XmlNode locationVisited = playerData.CreateElement("LocationVisited");
AddXmlAttributeToNode(playerData, locationVisited, "ID", locationID);
locationsVisited.AppendChild(locationVisited);
}
// Create the "InventoryItems" child node to hold each InventoryItem node
XmlNode inventoryItems = playerData.CreateElement("InventoryItems");
player.AppendChild(inventoryItems);
// Create an "InventoryItem" node for each item in the player's inventory
foreach (InventoryItem item in Inventory)
{
XmlNode inventoryItem = playerData.CreateElement("InventoryItem");
AddXmlAttributeToNode(playerData, inventoryItem, "ID", item.Details.ID);
AddXmlAttributeToNode(playerData, inventoryItem, "Quantity", item.Quantity);
inventoryItems.AppendChild(inventoryItem);
}
// Create the "PlayerQuests" child node to hold each PlayerQuest node
XmlNode playerQuests = playerData.CreateElement("PlayerQuests");
player.AppendChild(playerQuests);
// Create a "PlayerQuest" node for each quest the player has acquired
foreach (PlayerQuest quest in Quests)
{
XmlNode playerQuest = playerData.CreateElement("PlayerQuest");
AddXmlAttributeToNode(playerData, playerQuest, "ID", quest.Details.ID);
AddXmlAttributeToNode(playerData, playerQuest, "IsCompleted", quest.IsCompleted);
playerQuests.AppendChild(playerQuest);
}
return playerData.InnerXml; // The XML document, as a string, so we can save the data to disk
}
//
// Endo of Player XML Writer
// /////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////
// Start of Player XML Reader / Create Player From XML
//
public static Player CreatePlayerFromXmlString(string xmlPlayerData)
{
try
{
XmlDocument playerData = new XmlDocument();
playerData.LoadXml(xmlPlayerData);
int currentHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentHitPoints").InnerText);
int maximumHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaximumHitPoints").InnerText);
int gold = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Gold").InnerText);
int experiencePoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ExperiencePoints").InnerText);
int playerBaseHP = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/PlayerBaseHP").InnerText);
int playerBaseMP = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/PlayerBaseMP").InnerText);
int currentManaPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentManaPoints").InnerText);
int maxManaPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaxManaPoints").InnerText);
int magicSkillExperience = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MagicSKillExperience").InnerText);
int shieldSkillEXP = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ShieldSkillEXP").InnerText);
int attackSkillEXP = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/AttackSkillEXP").InnerText);
Player player = new Player(currentHitPoints, maximumHitPoints, gold, experiencePoints, playerBaseHP, playerBaseMP, currentManaPoints, maxManaPoints, magicSkillExperience, shieldSkillEXP, attackSkillEXP );
int currentLocationID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText);
player.CurrentLocation = World.LocationByID(currentLocationID);
if (playerData.SelectSingleNode("/Player/Stats/CurrentWeapon") != null)
{
int currentWeaponID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText);
player.CurrentWeapon = (Weapon)World.ItemByID(currentWeaponID);
}
if (playerData.SelectSingleNode("/Player/Stats/CurrentSpell") != null)
{
int currentSpellID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentSpell").InnerText);
player.CurrentSpell = (Spell)World.ItemByID(currentSpellID);
}
foreach (XmlNode node in playerData.SelectNodes("/Player/LocationsVisited/LocationVisited"))
{
int id = Convert.ToInt32(node.Attributes["ID"].Value);
player.LocationsVisited.Add(id);
}
foreach (XmlNode node in playerData.SelectNodes("/Player/InventoryItems/InventoryItem"))
{
int id = Convert.ToInt32(node.Attributes["ID"].Value);
int quantity = Convert.ToInt32(node.Attributes["Quantity"].Value);
for (int i = 0; i < quantity; i++)
{
player.AddItemToInventory(World.ItemByID(id));
}
}
foreach (XmlNode node in playerData.SelectNodes("/Player/PlayerQuests/PlayerQuest"))
{
int id = Convert.ToInt32(node.Attributes["ID"].Value);
bool isCompleted = Convert.ToBoolean(node.Attributes["IsCompleted"].Value);
PlayerQuest playerQuest = new PlayerQuest(World.QuestByID(id));
playerQuest.IsCompleted = isCompleted;
player.Quests.Add(playerQuest);
}
return player;
}
catch
{
// If there was an error with the XML data, return a default player object
return CreateDefaultPlayer();
}
}
// End Player XML Reader
// ////////////////////////////////////////////////////////////////
//
// End of XML File Reader
// ///////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
using Engine;
namespace SuperAdventure
{
public partial class SuperAdventure : Form
{
private const string PLAYER_DATA_FILE_NAME = "PlayerData.xml";
private Player _player;
// private Monster ActiveMonster;
public SuperAdventure()
{
InitializeComponent();
// ActiveMonster = Monster.CurrentMonster;
// ////////////////////////////////////////////////
// Load Player From Sql Data
//
// _player = PlayerDataMapper.CreateFromDatabase(); // <-- Load Player From Sql Data |||| ( Temp Disabled Whilst Modifying Will sql read/write will need Updateing before RE_ACTIVATING )
// SQL Info
// Make This An optional feature on client with abilty enter different sql conection String , either by UI or as setting file
// ////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////
// Load XML Player Data
if (_player == null)
{
if (File.Exists(PLAYER_DATA_FILE_NAME))
{
_player = Player.CreatePlayerFromXmlString(File.ReadAllText(PLAYER_DATA_FILE_NAME));
}
else
{
_player = Player.CreateDefaultPlayer();
}
}
/////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////////////////
// Set Display/Grid Labels Start
// maybe Add these into voids by grouping related ????
lblHitPoints.DataBindings.Add("Text", _player, "CurrentHitPoints");
lblGold.DataBindings.Add("Text", _player, "Gold");
lblExperience.DataBindings.Add("Text", _player, "ExperiencePoints");
lblLevel.DataBindings.Add("Text", _player, "Level");
lblManaPoints.DataBindings.Add("Text", _player, "CurrentManaPoints");
lblMagicEXP.DataBindings.Add("Text", _player, "MagicSkill");
lblMagicSkillEXP.DataBindings.Add("Text", _player, "MagicSKillExperience");
lblShieldSkill.DataBindings.Add("Text", _player, "ShieldSkill");
lblShieldSkillEXP.DataBindings.Add("Text", _player, "ShieldSkillEXP");
lblAttackSkill.DataBindings.Add("Text", _player, "AttackSkill");
lblAttackSkillEXP.DataBindings.Add("Text", _player, "AttackSkillEXP");
dgvInventory.RowHeadersVisible = false;
dgvInventory.AutoGenerateColumns = false;
dgvInventory.DataSource = _player.Inventory;
dgvInventory.Columns.Add(new DataGridViewTextBoxColumn
{
HeaderText = "Name",
Width = 197,
DataPropertyName = "Description"
});
dgvInventory.Columns.Add(new DataGridViewTextBoxColumn
{
HeaderText = "Quantity",
DataPropertyName = "Quantity"
});
dgvInventory.ScrollBars = ScrollBars.Vertical;
dgvQuests.RowHeadersVisible = false;
dgvQuests.AutoGenerateColumns = false;
dgvQuests.DataSource = _player.Quests;
dgvQuests.Columns.Add(new DataGridViewTextBoxColumn
{
HeaderText = "Name",
Width = 197,
DataPropertyName = "Name"
});
dgvQuests.Columns.Add(new DataGridViewTextBoxColumn
{
HeaderText = "Done?",
DataPropertyName = "IsCompleted"
});
cboWeapons.DataSource = _player.Weapons;
cboWeapons.DisplayMember = "Name";
cboWeapons.ValueMember = "Id";
if (_player.CurrentWeapon != null)
{
cboWeapons.SelectedItem = _player.CurrentWeapon;
}
cboWeapons.SelectedIndexChanged += cboWeapons_SelectedIndexChanged;
cboPotions.DataSource = _player.Potions;
cboPotions.DisplayMember = "Name";
cboPotions.ValueMember = "Id";
if (_player.CurrentPotion != null)
{
cboPotions.SelectedItem = _player.CurrentPotion;
}
cboSpells.DataSource = _player.Spells;
cboSpells.DisplayMember = "Name";
cboSpells.ValueMember = "Id";
if (_player.CurrentSpell != null)
{
cboSpells.SelectedItem = _player.CurrentSpell;
}
cboSpells.SelectedIndexChanged += cboSpells_SelectedIndexChanged;
_player.PropertyChanged += PlayerOnPropertyChanged;
_player.OnMessage += DisplayMessage;
// ////
_player.MoveTo(_player.CurrentLocation);
// ///
}
// Set Display/Grid Labes End
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void DisplayMessage(object sender, MessageEventArgs messageEventArgs)
{
rtbMessages.Text += messageEventArgs.Message + Environment.NewLine;
if (messageEventArgs.AddExtraNewLine)
{
rtbMessages.Text += Environment.NewLine;
}
rtbMessages.SelectionStart = rtbMessages.Text.Length;
rtbMessages.ScrollToCaret();
}
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////
// Progressbars/DisplayBars
private void UpdateDisplayBars ()
{
// ///////////////////////////////////////////////////////////////////////////////
// Progressbars/DisplayBars INT Used For Divede by 0 error And prents ValuesBelow 0 ,and not alter current values anywhere where else
int PlayersCurrentHP = _player.CurrentHitPoints;
int PlayersCurrentMP = _player.CurrentManaPoints;
int OldMagicSkillLevel_Bar = (_player.MagicSKillExperience - _player.OldMagicSkillLevel);
int NextMagicSkillLevel_Bar = (_player.NextMagicSkillLevel - _player.OldMagicSkillLevel);
int OldAttackSkillLevel_Bar = (_player.AttackSkillEXP - _player.OldAttackSkillLevel);
int NextAttackSkillLevel_Bar = (_player.NextAttackSkillLevel - _player.OldAttackSkillLevel);
int OldShieldSkillLevel_Bar = (_player.ShieldSkillEXP - _player.OldShieldSkillLevel);
int NextShieldSkillLevel_Bar = (_player.NextShieldSkillLevel - _player.OldShieldSkillLevel);
int OldLevel_Bar = (_player.ExperiencePoints - _player.OldlLevel);
int NextLevel_Bar = (_player.NextLevel - _player.OldlLevel);
///////////////////////////////////////////////////////////////////////
// prevents current stats returning a Value below 0 for the progress bars
if (OldMagicSkillLevel_Bar < 0)
{
OldMagicSkillLevel_Bar = 0;
}
if (OldAttackSkillLevel_Bar < 0)
{
OldAttackSkillLevel_Bar = 0;
}
if (OldShieldSkillLevel_Bar < 0)
{
OldShieldSkillLevel_Bar = 0;
}
if (OldLevel_Bar < 0)
{
OldLevel_Bar = 0;
}
if (PlayersCurrentHP < 0) // orriginally used _player.CurrentHitPoints but changed Due to thinking this way its not changing int value anywhere else
{
PlayersCurrentHP = 0;
}
if (PlayersCurrentMP < 0) // orriginally used _player.CurrentManaPoints but changed Due to thinking this way its not changing int value anywhere else
{
PlayersCurrentMP = 0;
}
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// Seems fixed
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// for some reason currenthitpoints ocassionaly returns value above maxHit points
// temp fix and prevention,, not sure why yet Possibly because Shield ANd Attack battle Mode values was going below 0
// if (_player.CurrentHitPoints > _player.MaximumHitPoints)
// {
// _player.CurrentHitPoints = _player.MaximumHitPoints;
//
//
// if (_player.CurrentManaPoints > _player.MaximumHitPoints)
// {
// _player.CurrentManaPoints = _player.MaximumHitPoints;
// }
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Progress Bars Functions. Caculates Display Bars Aaaprrox percentage
HealthBar.Value = (PlayersCurrentHP * 100 / _player.MaximumHitPoints);
ManaBar.Value = (PlayersCurrentMP * 100 / _player.MaxManaPoints);
MagicSkillBar.Value = (OldMagicSkillLevel_Bar * 100 / NextMagicSkillLevel_Bar);
AttackSkillBar.Value = (OldAttackSkillLevel_Bar * 100 / NextAttackSkillLevel_Bar); // ocassionaly getting divide by 0 error , Only Happens when max skill
ShieldSkillBar.Value = (OldShieldSkillLevel_Bar * 100 / NextShieldSkillLevel_Bar);
NextLevelBar.Value = (OldLevel_Bar * 100 / NextLevel_Bar);
// ////////////////////////
// Current Monster Health Bar
// MonsterHealthBar.Value = (ActiveMonster.CurrentHitPoints * 100 / ActiveMonster.MaximumHitPoints);
// ///////////////////////////
}
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void PlayerOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
{
// /////////////////////////////////////////////
// Calls Function To update Display Bars Values every time anything Changes // ????? working fine but is this a good way/place ????
UpdateDisplayBars();
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (propertyChangedEventArgs.PropertyName == "Weapons")
{
cboWeapons.DataSource = _player.Weapons;
if (!_player.Weapons.Any())
{
cboWeapons.Visible = false;
btnUseWeapon.Visible = false;
}
}
if (propertyChangedEventArgs.PropertyName == "Potions")
{
cboPotions.DataSource = _player.Potions;
if (!_player.Potions.Any())
{
cboPotions.Visible = false;
btnUsePotion.Visible = false;
}
}
if (propertyChangedEventArgs.PropertyName == "Spells")
{
cboSpells.DataSource = _player.Spells;
if (!_player.Spells.Any())
{
cboSpells.Visible = false;
btnSpellCast.Visible = false;
}
}
if (propertyChangedEventArgs.PropertyName == "CurrentLocation")
{
// Show/hide available movement buttons
btnNorth.Visible = (_player.CurrentLocation.LocationToNorth != null);
btnEast.Visible = (_player.CurrentLocation.LocationToEast != null);
btnSouth.Visible = (_player.CurrentLocation.LocationToSouth != null);
btnWest.Visible = (_player.CurrentLocation.LocationToWest != null);
btnTrade.Visible = (_player.CurrentLocation.VendorWorkingHere != null);
// Display current location name and description
rtbLocation.Text = _player.CurrentLocation.Name + Environment.NewLine;
rtbLocation.Text += _player.CurrentLocation.Description + Environment.NewLine;
if (!_player.CurrentLocation.HasAMonster)
{
cboWeapons.Visible = false;
cboPotions.Visible = false;
cboSpells.Visible = false;
btnUseWeapon.Visible = false;
btnUsePotion.Visible = false;
btnSpellCast.Visible = false;
}
else
{
cboWeapons.Visible = _player.Weapons.Any();
cboPotions.Visible = _player.Potions.Any();
cboSpells.Visible = _player.Spells.Any();
btnUseWeapon.Visible = _player.Weapons.Any();
btnUsePotion.Visible = _player.Potions.Any();
btnSpellCast.Visible = _player.Spells.Any();
}
}
if(propertyChangedEventArgs.PropertyName == "CurrentMonster")
{
if(_player.CurrentMonster != null)
{
_player.CurrentMonster.PropertyChanged += CurrentMonster_PropertyChanged;
DisplayMonsterHealthProgressBar();
}
}
}
private void CurrentMonster_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
DisplayMonsterHealthProgressBar();
}
private void DisplayMonsterHealthProgressBar()
{
MonsterHealthBar.Value = (Math.Max(0, _player.CurrentMonster.CurrentHitPoints) * 100 / _player.CurrentMonster.MaximumHitPoints);
}
// // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void btnNorth_Click(object sender, EventArgs e)
{
_player.MoveNorth();
}
private void btnEast_Click(object sender, EventArgs e)
{
_player.MoveEast();
}
private void btnSouth_Click(object sender, EventArgs e)
{
_player.MoveSouth();
}
private void btnWest_Click(object sender, EventArgs e)
{
_player.MoveWest();
}
private void btnUseWeapon_Click(object sender, EventArgs e)
{
// Get the currently selected weapon from the cboWeapons ComboBox
Weapon currentWeapon = (Weapon)cboWeapons.SelectedItem;
_player.UseWeapon(currentWeapon);
}
private void cboWeapons_SelectedIndexChanged(object sender, EventArgs e)
{
_player.CurrentWeapon = (Weapon)cboWeapons.SelectedItem;
}
private void btnUsePotion_Click(object sender, EventArgs e)
{
// Get the currently selected potion from the combobox
HealingPotion CurrentPotion = (HealingPotion)cboPotions.SelectedItem;
_player.UsePotion(CurrentPotion);
}
private void cboPotions_SelectedIndexChanged(object sender, EventArgs e)
{
_player.CurrentPotion = (HealingPotion)cboPotions.SelectedItem;
}
private void btnTrade_Click(object sender, EventArgs e)
{
TradingScreen tradingScreen = new TradingScreen(_player);
tradingScreen.StartPosition = FormStartPosition.CenterParent;
tradingScreen.ShowDialog(this);
}
private void btnMap_Click(object sender, EventArgs e)
{
WorldMap mapScreen = new WorldMap(_player);
mapScreen.StartPosition = FormStartPosition.CenterParent;
mapScreen.ShowDialog(this);
}
private void btnSpellCast_Click(object sender, EventArgs e)
{
// Get the currently selected potion from the combobox
Spell currentspell = (Spell)cboSpells.SelectedItem;
if (_player.CurrentManaPoints < currentspell.ManaCost)
{
MessageBox.Show("You do not have "+ currentspell.ManaCost + " Mana Points " );
}
else
{
_player.UseSpells(currentspell);
}
}
private void cboSpells_SelectedIndexChanged(object sender, EventArgs e)
{
_player.CurrentSpell = (Spell)cboSpells.SelectedItem;
}
private void SuperAdventure_FormClosing(object sender, FormClosingEventArgs e)
{
File.WriteAllText(PLAYER_DATA_FILE_NAME, _player.ToXmlString());
// PlayerDataMapper.SaveToDatabase(_player);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment