[arthea] r471 committed - [No log message]

0 views
Skip to first unread message

art...@googlecode.com

unread,
Apr 21, 2011, 8:20:39 PM4/21/11
to arthea-...@googlegroups.com
Revision: 471
Author: c0der78
Date: Thu Apr 21 17:19:32 2011
Log: [No log message]
http://code.google.com/p/arthea/source/detail?r=471

Modified:
/trunk/ArtheaEngine/Combat.cs
/trunk/ArtheaEngine/Model/Area.cs
/trunk/ArtheaEngine/Model/Character.cs
/trunk/ArtheaEngine/Model/Player.cs
/trunk/ArtheaEngine/Model/World.cs
/trunk/ArtheaServer/Commands/KillCommand.cs
/trunk/arthea.sql

=======================================
--- /trunk/ArtheaEngine/Combat.cs Wed Apr 20 20:08:14 2011
+++ /trunk/ArtheaEngine/Combat.cs Thu Apr 21 17:19:32 2011
@@ -2,6 +2,7 @@
{
using System;
using System.Collections.Generic;
+ using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

@@ -9,29 +10,38 @@

public class Combat : ITickable
{
+ #region Fields
+
+ private Character _thisChar;
+
+ #endregion Fields
+
#region Constructors

- public Combat(Character ch, Character victim)
- {
- Attacker = ch;
- Victim = victim;
+ public Combat(Character ch, params Character[] victims)
+ {
+ _thisChar = ch;
+ Victims = new HashSet<Character>();
+ foreach (var victim in victims)
+ Victims.Add(victim);
}

#endregion Constructors

#region Properties

- public Character Attacker
- {
- get; private set;
+ public int Speed
+ {
+ get;
+ set;
}

public int TickInterval
{
- get { return 1000; }
+ get { return Speed; }
}

- public Character Victim
+ public ISet<Character> Victims
{
get; private set;
}
@@ -40,64 +50,114 @@

#region Methods

- public void Tick()
- {
- int[] attacks = Attacker.Attack.RollAgainst(Victim.Defense);
+ public void Attack(Character victim)
+ {
+ int[] attacks = _thisChar.Attack.RollAgainst(victim.Defense);

foreach (var bonus in attacks)
{
- var damage =
Attacker.Attack.RollAgainstValue(Victim.Defense);
+ var damage =
_thisChar.Attack.RollAgainstValue(victim.Defense);

damage += bonus;

- Victim.Vitals.Life -= damage;
-
- DamMessage(Attacker, Victim, damage);
-
- if (Victim.Vitals.Life <= 0)
- {
- End();
+ victim.Vitals.Life -= damage;
+
+ DamMessage(victim, damage, false);
+
+ if (victim.Vitals.Life <= 0)
+ {
+ Die(victim);
return;
}
}

- int counterAttacks = Victim.Attack.Count - attacks.Length;
+ CounterAttack(victim, attacks.Length);
+ }
+
+ public void DisplayPrompt()
+ {
+ if (_thisChar is Player)
+ {
+ (_thisChar as Player).DisplayPrompt();
+ }
+ }
+
+ public void Tick()
+ {
+ foreach (var victim in Victims)
+ {
+ Attack(victim);
+
+ _thisChar.WriteLine();
+ victim.WriteLine();
+ }
+
+ DisplayPrompt();
+ }
+
+ private void CounterAttack(Character victim, int attacks)
+ {
+ int counterAttacks = victim.Attack.Count - attacks;

for (var i = 0; i < counterAttacks; i++)
{
- var damage =
Victim.Attack.RollAgainstValue(Attacker.Defense);
- Attacker.Vitals.Life -= damage;
-
- DamMessage(Victim, Attacker, damage);
-
- if (Attacker.Vitals.Life <= 0)
- {
- End();
+ var damage =
victim.Attack.RollAgainstValue(_thisChar.Defense);
+ _thisChar.Vitals.Life -= damage;
+
+ DamMessage(victim, damage, true);
+
+ if (_thisChar.Vitals.Life <= 0)
+ {
+ Die(victim);
return;
}
}
-
- if (Attacker is Player)
- {
- Attacker.WriteLine();
- (Attacker as Player).DisplayPrompt();
- }
- }
-
- private void DamMessage(Character a, Character b, int damage)
- {
- a.Act("You hit {0} for {1} damage!", b, damage);
- b.Act("{0} hits you for {1} damage!", a, damage);
- b.Room.Act(new[] { a, b }, "{0} hits {1} for {2} damage!", a,
b, damage);
+ }
+
+ private void DamMessage(Character victim, int damage, bool counter)
+ {
+ Character a, b;
+ string vp, vs;
+ if (counter)
+ {
+ a = victim; b = _thisChar;
+ vs = "counter";
+ vp = "counters";
+ }
+ else
+ {
+ a = _thisChar; b = victim;
+ vs = "hit";
+ vp = "hits";
+ }
+
+ if (damage > 0)
+ {
+ a.Act("You {0} {1} for {2} damage!", vs, b, damage);
+ b.Act("{0} {1} you for {2} damage!", a, vp, damage);
+ b.Room.Act(new[] { a, b }, "{0} {1} {2} for {3} damage!",
a, vp, b, damage);
+ }
+ else
+ {
+ a.Act("You miss {1}.", b);
+ b.Act("{0} misses you with thier {1}.", a, vs);
+ b.Room.Act(new[] { a, b }, "{0} misses {1} with thier
{2}.", a, b, vs);
+ }
}

- private void End()
- {
- Victim.WriteLine("~RYou are DEAD!~x");
- Attacker.WriteLine("{0} is ~RDEAD!~x", Victim);
- Victim.Room.Act(new[] { Attacker, Victim }, "{0} is dead",
Victim);
- UpdateManager.Remove(Attacker.Fighting);
- UpdateManager.Remove(Victim.Fighting);
+ private void Die(Character victim)
+ {
+ victim.WriteLine("~RYou are DEAD!~x");
+ _thisChar.WriteLine("{0} is ~RDEAD!~x", victim);
+ victim.Room.Act(new[] { _thisChar, victim }, "{0} is dead",
victim);
+ UpdateManager.Remove(victim.Fighting);
+ UpdateManager.Remove(_thisChar.Fighting);
+ victim.Fighting = null;
+ _thisChar.Fighting = null;
+ if (victim is NonPlayer)
+ {
+ victim.Dispose();
+ }
}

#endregion Methods
=======================================
--- /trunk/ArtheaEngine/Model/Area.cs Wed Apr 20 20:08:14 2011
+++ /trunk/ArtheaEngine/Model/Area.cs Thu Apr 21 17:19:32 2011
@@ -40,7 +40,7 @@
n.Area = a ? this : null;
});

- TickInterval = ArtheaHelper.Randomizer.Next(6000, 12000);
+ TickInterval = ArtheaHelper.Randomizer.Next(90000, 120000);
}

#endregion Constructors
@@ -209,7 +209,7 @@
Name = reader.GetString(i++);
Credits = reader.GetString(i++);
World = World.List.SingleOrDefault(x => x.Id ==
reader.GetInt32(i++));
-
+
return i;
}

=======================================
--- /trunk/ArtheaEngine/Model/Character.cs Wed Apr 20 17:02:20 2011
+++ /trunk/ArtheaEngine/Model/Character.cs Thu Apr 21 17:19:32 2011
@@ -233,53 +233,6 @@
return List.OfType<T>().FirstOrDefault(x =>
x.Name.HasWord(name));
}

- /*
- public virtual void Act(ActType type, string format, params
object[] args)
- {
- var temp = new List<object> { this };
- temp.AddRange(args);
- args = temp.ToArray();
-
- if ((type & ActType.Char) != 0)
- {
- WriteLine(string.Format(new ActionFormatter(this), format,
args));
- }
-
- if ((type & ActType.Room) != 0)
- {
- foreach (var ch in Room.Characters)
- {
- if (ch == this) continue;
-
- ch.WriteLine(string.Format(new ActionFormatter(ch),
format, args));
- }
- }
-
- if ((type & ActType.NotChar) != 0)
- {
- foreach (var ch in Room.Characters)
- {
- if (ch == this) continue;
-
- if (args.Length > 1 && args[1] is Character && args[1]
== ch)
- continue;
-
- ch.WriteLine(string.Format(new ActionFormatter(ch),
format, args));
- }
- }
-
- if ((type & ActType.World) != 0)
- {
- foreach (var ch in World.Connections)
- {
- if (ch.Playing == this)
- continue;
-
- ch.WriteLine(string.Format(new
ActionFormatter(ch.Playing), format, args));
- }
- }
- }
- */
public void Act(string format, params object[] args)
{
WriteLine(string.Format(new ActionFormatter(this), format,
args));
@@ -541,12 +494,6 @@

public class Vitals
{
- #region Fields
-
- public int MaxLife;
-
- #endregion Fields
-
#region Constructors

public Vitals()
@@ -554,44 +501,38 @@
Life = MaxLife=100;
Mana = MaxMana = 100;
Energy = MaxEnergy = 100;
- WillPower = MaxWillPower = 100;
}

#endregion Constructors

#region Properties

- public int Energy
+ public long Energy
{
get; set;
}

- public int Life
+ public long Life
{
get; set;
}

- public int Mana
+ public long Mana
{
get; set;
}

- public int MaxEnergy
+ public long MaxEnergy
{
get; set;
}

- public int MaxMana
+ public long MaxLife
{
get; set;
}

- public int MaxWillPower
- {
- get; set;
- }
-
- public int WillPower
+ public long MaxMana
{
get; set;
}
=======================================
--- /trunk/ArtheaEngine/Model/Player.cs Wed Apr 20 17:02:20 2011
+++ /trunk/ArtheaEngine/Model/Player.cs Thu Apr 21 17:19:32 2011
@@ -200,6 +200,13 @@
if (Class == null)
Class = new MageClass();

+ Vitals.Life = reader.GetInt64(i++);
+ Vitals.MaxLife = reader.GetInt64(i++);
+ Vitals.Mana = reader.GetInt64(i++);
+ Vitals.MaxMana = reader.GetInt64(i++);
+ Vitals.Energy = reader.GetInt64(i++);
+ Vitals.MaxEnergy = reader.GetInt64(i++);
+
return i;
}

@@ -223,6 +230,12 @@
cmd.AddParameter("@chan_flags", DbType.String,
ChannelFlags.ToString());
cmd.AddParameter("@account", DbType.Int64, Account.Id);
cmd.AddParameter("@class", DbType.Int32, Class.Id);
+ cmd.AddParameter("@life", DbType.Int64, Vitals.Life);
+ cmd.AddParameter("@max_life", DbType.Int64, Vitals.MaxLife);
+ cmd.AddParameter("@mana", DbType.Int64, Vitals.Mana);
+ cmd.AddParameter("@max_mana", DbType.Int64, Vitals.MaxMana);
+ cmd.AddParameter("@energy", DbType.Int64, Vitals.Energy);
+ cmd.AddParameter("@max_energy", DbType.Int64,
Vitals.MaxEnergy);

var res = cmd.ExecuteNonQuery() > 0;

=======================================
--- /trunk/ArtheaEngine/Model/World.cs Wed Apr 20 20:08:14 2011
+++ /trunk/ArtheaEngine/Model/World.cs Thu Apr 21 17:19:32 2011
@@ -206,6 +206,8 @@
area.LoadNpcs(conn);
area.LoadObjects(conn);
area.LoadRooms(conn);
+
+ area.Tick();
}
}

=======================================
--- /trunk/ArtheaServer/Commands/KillCommand.cs Wed Apr 20 17:02:20 2011
+++ /trunk/ArtheaServer/Commands/KillCommand.cs Thu Apr 21 17:19:32 2011
@@ -33,11 +33,13 @@

ch.Fighting = new Combat(ch, victim);

- UpdateManager.Add(ch.Fighting);
-
victim.Fighting = new Combat(victim, ch);

+ UpdateManager.Add(ch.Fighting);
+
UpdateManager.Add(victim.Fighting);
+
+ ch.Fighting.Tick(); // do something right away
}

#endregion Methods
=======================================
--- /trunk/arthea.sql Wed Apr 20 17:02:20 2011
+++ /trunk/arthea.sql Thu Apr 21 17:19:32 2011
@@ -293,6 +293,12 @@
`channel_flags` tinytext,
`account_id` bigint(20) NOT NULL,
`class_id` int(11) DEFAULT NULL,
+ `life` bigint(20) NOT NULL DEFAULT '100',
+ `max_life` bigint(20) NOT NULL DEFAULT '100',
+ `mana` bigint(20) NOT NULL DEFAULT '100',
+ `max_mana` bigint(20) NOT NULL DEFAULT '100',
+ `energy` bigint(20) NOT NULL DEFAULT '100',
+ `max_energy` bigint(20) NOT NULL DEFAULT '100',
PRIMARY KEY (`char_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -1927,7 +1933,13 @@
`@title` varchar(145),
`@chan_flags` tinytext,
`@account` bigint,
- `@class` int
+ `@class` int,
+ `@life` bigint,
+ `@max_life` bigint,
+ `@mana` bigint,
+ `@max_mana` bigint,
+ `@energy` bigint,
+ `@max_energy` bigint
)
BEGIN
INSERT INTO `arthea`.`player` (
@@ -1936,14 +1948,26 @@
`title`,
`channel_flags`,
`account_id`,
- `class_id`
+ `class_id`,
+ `life`,
+ `max_life`,
+ `mana`,
+ `max_mana`,
+ `energy`,
+ `max_energy`
) VALUES (
`@id`,
`@room`,
`@title`,
`@chan_flags`,
`@account`,
- `@class`
+ `@class`,
+ `@life`,
+ `@max_life`,
+ `@mana`,
+ `@max_mana`,
+ `@energy`,
+ `@max_energy`
)
ON DUPLICATE KEY
UPDATE
@@ -1951,7 +1975,12 @@
`title` = `@title`,
`channel_flags` = `@chan_flags`,
`account_id` = `@account`,
- `class_id` = `@class`;
+ `class_id` = `@class`,
+ `life` = `@life`,
+ `max_life` = `@max_life`,
+ `mana` = `@max_mana`,
+ `energy` = `@energy`,
+ `max_energy` = `@max_energy`;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -2582,4 +2611,4 @@
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

--- Dump completed on 2011-04-20 16:58:56
+-- Dump completed on 2011-04-21 17:18:44

Reply all
Reply to author
Forward
0 new messages