[Calindor-commits] SF.net SVN: calindor: [105] trunk/src/server
Status: Pre-Alpha
Brought to you by:
deadwood_pl
From: <dea...@us...> - 2008-01-01 21:05:13
|
Revision: 105 http://calindor.svn.sourceforge.net/calindor/?rev=105&view=rev Author: deadwood_pl Date: 2008-01-01 13:05:08 -0800 (Tue, 01 Jan 2008) Log Message: ----------- Change activation method of actions Modified Paths: -------------- trunk/src/server/EntityImplementation.cs trunk/src/server/EntityImplementationSkills.cs trunk/src/server/ServerCharacter.cs trunk/src/server/TimeBasedActions.cs Modified: trunk/src/server/EntityImplementation.cs =================================================================== --- trunk/src/server/EntityImplementation.cs 2008-01-01 20:29:24 UTC (rev 104) +++ trunk/src/server/EntityImplementation.cs 2008-01-01 21:05:08 UTC (rev 105) @@ -88,14 +88,15 @@ timeBasedActionAddActionToManager(actionToExecute); } - + public void TimeBasedActionRemoveExecuted() + { + executedTimeBasedAction = null; + } + public void TimeBasedActionCancelExecuted() { if (executedTimeBasedAction != null) - { executedTimeBasedAction.Cancel(); - executedTimeBasedAction = null; - } } #endregion @@ -221,7 +222,8 @@ return; // Add walk time based action - TimeBasedActionSetExecuted(new WalkTimeBasedAction(this, path)); + WalkTimeBasedAction walk = new WalkTimeBasedAction(this, path); + walk.Activate(); // Move followers Modified: trunk/src/server/EntityImplementationSkills.cs =================================================================== --- trunk/src/server/EntityImplementationSkills.cs 2008-01-01 20:29:24 UTC (rev 104) +++ trunk/src/server/EntityImplementationSkills.cs 2008-01-01 21:05:08 UTC (rev 105) @@ -25,8 +25,9 @@ #region Harvest Skills public void HarvestStart(HarvestableResourceDescriptor rscDef) { - TimeBasedActionSetExecuted( - new HarvestTimeBasedAction(this, rscDef)); + HarvestTimeBasedAction harvest = + new HarvestTimeBasedAction(this, rscDef); + harvest.Activate(); RawTextOutgoingMessage msgRawText = (RawTextOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.RAW_TEXT); @@ -194,13 +195,11 @@ defender.PutMessageIntoMyAndObserversQueue(msgAddActorCommandDefender); // Checks ok. Start combat - AttackTimeBasedAction attackDefender = new AttackTimeBasedAction(this, defender); - TimeBasedActionSetExecuted(attackDefender); - defender.TimeBasedActionAddAffecting(attackDefender); + AttackTimeBasedAction attackDefender = new AttackTimeBasedAction(this, defender); + attackDefender.Activate(); // TODO: Only if defender is not attacking anyone already AttackTimeBasedAction attackAttacker = new AttackTimeBasedAction(defender, this); - defender.TimeBasedActionSetExecuted(attackAttacker); - TimeBasedActionAddAffecting(attackAttacker); + attackAttacker.Activate(); } public void CombatAttack(EntityImplementation defender) Modified: trunk/src/server/ServerCharacter.cs =================================================================== --- trunk/src/server/ServerCharacter.cs 2008-01-01 20:29:24 UTC (rev 104) +++ trunk/src/server/ServerCharacter.cs 2008-01-01 21:05:08 UTC (rev 105) @@ -378,7 +378,7 @@ // Respawn RespawnTimeBasedAction respawn = new RespawnTimeBasedAction(this, milisToRespawn); - TimeBasedActionSetExecuted(respawn); + respawn.Activate(); } Modified: trunk/src/server/TimeBasedActions.cs =================================================================== --- trunk/src/server/TimeBasedActions.cs 2008-01-01 20:29:24 UTC (rev 104) +++ trunk/src/server/TimeBasedActions.cs 2008-01-01 21:05:08 UTC (rev 105) @@ -77,7 +77,12 @@ /// <summary> /// Causes the action to be canceled /// </summary> - void Cancel(); + void Cancel(); + + /// <summary> + /// Call this method, to 'activate' the action + /// </summary> + void Activate(); } public class TimeBasedActionList : List<ITimeBasedAction> @@ -89,16 +94,28 @@ /// </summary> public abstract class TimeBasedAction : TimeBasedExecution, ITimeBasedAction { - protected EntityImplementation targetEntityImplementation = null; + protected EntityImplementation executingEntityImplementation = null; + protected EntityImplementation affectedEntityImplementation = null; private bool actionCanceled = false; protected bool shouldContinue = true; - protected TimeBasedAction(EntityImplementation enImpl, uint actionDuration):base(actionDuration) + protected TimeBasedAction(EntityImplementation executing, uint actionDuration): + base(actionDuration) { - if (enImpl == null) - throw new ArgumentNullException("enImpl"); + if (executing == null) + throw new ArgumentNullException("executing"); - targetEntityImplementation = enImpl; + executingEntityImplementation = executing; + } + + // TODO: Maybe pass array of affected entities? + protected TimeBasedAction(EntityImplementation executing, + EntityImplementation affected, uint actionDuration): + this(executing, actionDuration) + { + if (affected == null) + throw new NullReferenceException("affected"); + affectedEntityImplementation = affected; } protected override PreconditionsResult checkPreconditions() @@ -110,19 +127,31 @@ } else return PreconditionsResult.EXECUTE; - } + } + + #region ITimeBasedAction Members public virtual void Cancel() { - actionCanceled = true; + actionCanceled = true; + executingEntityImplementation.TimeBasedActionRemoveExecuted(); + if (affectedEntityImplementation != null) + affectedEntityImplementation.TimeBasedActionRemoveAffecting(this); } public bool ShouldContinue { get { return shouldContinue; } } + + public void Activate() + { + executingEntityImplementation.TimeBasedActionSetExecuted(this); + if (affectedEntityImplementation != null) + affectedEntityImplementation.TimeBasedActionAddAffecting(this); + } #endregion } @@ -158,7 +187,7 @@ numberOfMoves++; // Add one move firstStep = false; // No longer first step walkPath.GetNext(); // Remove the first item (current location) from path - targetEntityImplementation.LocationStandUp(true); // Stand up + executingEntityImplementation.LocationStandUp(true); // Stand up } for (int i = 0; i < numberOfMoves; i++) @@ -174,8 +203,8 @@ } // Check if location is not occupied - if (targetEntityImplementation.LocationCurrentMap.IsLocationOccupied(itm.X, itm.Y, - targetEntityImplementation.LocationDimension)) + if (executingEntityImplementation.LocationCurrentMap.IsLocationOccupied(itm.X, itm.Y, + executingEntityImplementation.LocationDimension)) { shouldContinue = false; return; // TODO: Needs to reroute @@ -183,8 +212,8 @@ // Check direction - int xDiff = targetEntityImplementation.LocationX - itm.X; - int yDiff = targetEntityImplementation.LocationY - itm.Y; + int xDiff = executingEntityImplementation.LocationX - itm.X; + int yDiff = executingEntityImplementation.LocationY - itm.Y; if (Math.Abs(xDiff) > 1 || Math.Abs(yDiff) > 1) { @@ -195,34 +224,34 @@ if (xDiff == 0) { if (yDiff == -1) - targetEntityImplementation.LocationTakeStep(PredefinedDirection.N); + executingEntityImplementation.LocationTakeStep(PredefinedDirection.N); if (yDiff == 1) - targetEntityImplementation.LocationTakeStep(PredefinedDirection.S); + executingEntityImplementation.LocationTakeStep(PredefinedDirection.S); } if (xDiff == -1) { if (yDiff == -1) - targetEntityImplementation.LocationTakeStep(PredefinedDirection.NE); + executingEntityImplementation.LocationTakeStep(PredefinedDirection.NE); if (yDiff == 0) - targetEntityImplementation.LocationTakeStep(PredefinedDirection.E); + executingEntityImplementation.LocationTakeStep(PredefinedDirection.E); if (yDiff == 1) - targetEntityImplementation.LocationTakeStep(PredefinedDirection.SE); + executingEntityImplementation.LocationTakeStep(PredefinedDirection.SE); } if (xDiff == 1) { if (yDiff == 1) - targetEntityImplementation.LocationTakeStep(PredefinedDirection.SW); + executingEntityImplementation.LocationTakeStep(PredefinedDirection.SW); if (yDiff == 0) - targetEntityImplementation.LocationTakeStep(PredefinedDirection.W); + executingEntityImplementation.LocationTakeStep(PredefinedDirection.W); if (yDiff == -1) - targetEntityImplementation.LocationTakeStep(PredefinedDirection.NW); + executingEntityImplementation.LocationTakeStep(PredefinedDirection.NW); } } @@ -258,8 +287,8 @@ private void calculateParameters() { - this.successRate = targetEntityImplementation.HarvestGetSuccessRate(rscDef); - setMilisBetweenExecutions(targetEntityImplementation.HarvestGetActionTime(rscDef)); + this.successRate = executingEntityImplementation.HarvestGetSuccessRate(rscDef); + setMilisBetweenExecutions(executingEntityImplementation.HarvestGetActionTime(rscDef)); } public override void Cancel() @@ -271,13 +300,13 @@ msgRawText.Channel = PredefinedChannel.CHAT_LOCAL; msgRawText.Color = PredefinedColor.Blue1; msgRawText.Text = "You stopped harvesting " + rscDef.HarvestedItem.Name; - targetEntityImplementation.PutMessageIntoMyQueue(msgRawText); + executingEntityImplementation.PutMessageIntoMyQueue(msgRawText); } protected override void execute() { if (WorldRNG.NextDouble() <= successRate) - targetEntityImplementation.HarvestItemHarvested(rscDef); + executingEntityImplementation.HarvestItemHarvested(rscDef); // After each harvest, recalculate calculateParameters(); @@ -295,7 +324,7 @@ protected override void execute() { - (targetEntityImplementation as ServerCharacter).EnergiesRespawn(); + (executingEntityImplementation as ServerCharacter).EnergiesRespawn(); shouldContinue = false; } @@ -304,30 +333,25 @@ // TODO: PROTOTYPE IMPLEMENTATION public class AttackTimeBasedAction : TimeBasedAction { - protected EntityImplementation defenderEntityImplementation = null; - + public AttackTimeBasedAction(EntityImplementation attacker, EntityImplementation defender): - base(attacker, 2000) // TODO: Fixed for now + base(attacker, defender, 2000) // TODO: Fixed for now { - if (defender == null) - throw new ArgumentNullException("defender"); - - defenderEntityImplementation = defender; } protected override void execute() { //TODO: Implement - targetEntityImplementation.CombatAttack(defenderEntityImplementation); - defenderEntityImplementation.CombatDefend(); - if (!defenderEntityImplementation.EnergiesIsAlive) + executingEntityImplementation.CombatAttack(affectedEntityImplementation); + affectedEntityImplementation.CombatDefend(); + if (!affectedEntityImplementation.EnergiesIsAlive) Cancel(); } public override void Cancel() { base.Cancel(); - targetEntityImplementation.CombatStopFighting(); + executingEntityImplementation.CombatStopFighting(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |