[Rpgworldmodel-commits] SF.net SVN: rpgworldmodel: [15] src/RPGWorldModel.Abstracts
Status: Inactive
Brought to you by:
deadwood_pl
From: <dea...@us...> - 2006-07-14 16:42:56
|
Revision: 15 Author: deadwood_pl Date: 2006-07-14 09:42:36 -0700 (Fri, 14 Jul 2006) ViewCVS: http://svn.sourceforge.net/rpgworldmodel/?rev=15&view=rev Log Message: ----------- More work on equipment. Support for multi-slot entites. Modified Paths: -------------- src/RPGWorldModel.Abstracts/EquipmentLocation.cs src/RPGWorldModel.Abstracts/EquipmentSlot.cs src/RPGWorldModel.Abstracts/Humanoid.cs src/RPGWorldModel.Abstracts/IEquip.cs src/RPGWorldModel.Abstracts/Sword.cs src/RPGWorldModel.Implementation/Swords.cs src/test_applications/tester/Form1.Designer.cs src/test_applications/tester/Form1.cs src/test_applications/tester/tester.csproj Modified: src/RPGWorldModel.Abstracts/EquipmentLocation.cs =================================================================== --- src/RPGWorldModel.Abstracts/EquipmentLocation.cs 2006-07-12 17:52:16 UTC (rev 14) +++ src/RPGWorldModel.Abstracts/EquipmentLocation.cs 2006-07-14 16:42:36 UTC (rev 15) @@ -46,6 +46,8 @@ { } + // Locations + public class EquipmentLocationLeftHand : EquipmentLocation { } @@ -61,4 +63,45 @@ public class EquipmentLocationWaist : EquipmentLocation { } + + public class EquipmentLocationHead : EquipmentLocation + { + } + + public class EquipmentLocationFace : EquipmentLocation + { + } + + public class EquipmentLocationTorso : EquipmentLocation + { + } + + public class EquipmentLocationLeftArm : EquipmentLocation + { + } + + public class EquipmentLocationRightArm : EquipmentLocation + { + } + + public class EquipmentLocationLeftLeg : EquipmentLocation + { + } + + public class EquipmentLocationRightLeg : EquipmentLocation + { + } + + public class EquipmentLocationLeftFoot : EquipmentLocation + { + } + + public class EquipmentLocationRightFoot : EquipmentLocation + { + } + + public class EquipmentLocationNeck : EquipmentLocation + { + } + } Modified: src/RPGWorldModel.Abstracts/EquipmentSlot.cs =================================================================== --- src/RPGWorldModel.Abstracts/EquipmentSlot.cs 2006-07-12 17:52:16 UTC (rev 14) +++ src/RPGWorldModel.Abstracts/EquipmentSlot.cs 2006-07-14 16:42:36 UTC (rev 15) @@ -12,21 +12,13 @@ get { return equippedEntities; } } - //TEST - protected EquipmentLocationList acceptableEquipmentLocations = new EquipmentLocationList(); - - public bool IsLocationAcceptable(EquipmentLocation location) + public int EquippedEntitiesCount { - foreach (EquipmentLocation acceptableLocation in acceptableEquipmentLocations) - { - if (acceptableLocation.GetType() == location.GetType()) - return true; - } - - return false; + get { return equippedEntities.Count; } } - // + public abstract bool IsLocationAcceptable(EquipmentLocation location); + public void AddEquipable(IEquipable equipable) { equippedEntities.Add(equipable); @@ -47,15 +39,21 @@ { } + // Slots + public class EquipmentSlotHead : EquipmentSlot { - public EquipmentSlotHead() + public override string SlotName { + get { return "Head"; } } - public override string SlotName + public override bool IsLocationAcceptable(EquipmentLocation location) { - get { return "Head"; } + if (location is EquipmentLocationHead) + return true; + else + return false; } } @@ -65,6 +63,14 @@ { get { return "Face"; } } + + public override bool IsLocationAcceptable(EquipmentLocation location) + { + if (location is EquipmentLocationFace) + return true; + else + return false; + } } public class EquipmentSlotNeck : EquipmentSlot @@ -73,6 +79,14 @@ { get { return "Neck"; } } + + public override bool IsLocationAcceptable(EquipmentLocation location) + { + if (location is EquipmentLocationNeck) + return true; + else + return false; + } } public class EquipmentSlotTorso : EquipmentSlot @@ -81,31 +95,45 @@ { get { return "Torso"; } } + + public override bool IsLocationAcceptable(EquipmentLocation location) + { + if (location is EquipmentLocationTorso) + return true; + else + return false; + } } public class EquipmentSlotWaist : EquipmentSlot { - public EquipmentSlotWaist() + public override string SlotName { - acceptableEquipmentLocations.Add(new EquipmentLocationWaist()); + get { return "Waist"; } } - public override string SlotName + public override bool IsLocationAcceptable(EquipmentLocation location) { - get { return "Waist"; } + if (location is EquipmentLocationWaist) + return true; + else + return false; } } public class EquipmentSlotBack : EquipmentSlot { - public EquipmentSlotBack() + public override string SlotName { - acceptableEquipmentLocations.Add(new EquipmentLocationBack()); + get { return "Back"; } } - public override string SlotName + public override bool IsLocationAcceptable(EquipmentLocation location) { - get { return "Back"; } + if (location is EquipmentLocationBack) + return true; + else + return false; } } @@ -115,6 +143,14 @@ { get { return "Left Arm"; } } + + public override bool IsLocationAcceptable(EquipmentLocation location) + { + if (location is EquipmentLocationLeftArm) + return true; + else + return false; + } } public class EquipmentSlotRightArm : EquipmentSlot @@ -123,31 +159,45 @@ { get { return "Right Arm"; } } + + public override bool IsLocationAcceptable(EquipmentLocation location) + { + if (location is EquipmentLocationRightArm) + return true; + else + return false; + } } public class EquipmentSlotLeftHand : EquipmentSlot { - public EquipmentSlotLeftHand() + public override string SlotName { - acceptableEquipmentLocations.Add(new EquipmentLocationLeftHand()); + get { return "Left Hand"; } } - public override string SlotName + public override bool IsLocationAcceptable(EquipmentLocation location) { - get { return "Left Hand"; } + if (location is EquipmentLocationLeftHand) + return true; + else + return false; } } public class EquipmentSlotRightHand : EquipmentSlot { - public EquipmentSlotRightHand() + public override string SlotName { - acceptableEquipmentLocations.Add(new EquipmentLocationRightHand()); + get { return "Right Hand"; } } - public override string SlotName + public override bool IsLocationAcceptable(EquipmentLocation location) { - get { return "Right Hand"; } + if (location is EquipmentLocationRightHand) + return true; + else + return false; } } @@ -157,6 +207,14 @@ { get { return "Left Leg"; } } + + public override bool IsLocationAcceptable(EquipmentLocation location) + { + if (location is EquipmentLocationLeftLeg) + return true; + else + return false; + } } public class EquipmentSlotRightLeg : EquipmentSlot @@ -165,6 +223,14 @@ { get { return "Right Leg"; } } + + public override bool IsLocationAcceptable(EquipmentLocation location) + { + if (location is EquipmentLocationRightLeg) + return true; + else + return false; + } } public class EquipmentSlotLeftFoot : EquipmentSlot @@ -173,6 +239,14 @@ { get { return "Left Foot"; } } + + public override bool IsLocationAcceptable(EquipmentLocation location) + { + if (location is EquipmentLocationLeftFoot) + return true; + else + return false; + } } public class EquipmentSlotRightFoot : EquipmentSlot @@ -181,5 +255,13 @@ { get { return "Right Foot"; } } + + public override bool IsLocationAcceptable(EquipmentLocation location) + { + if (location is EquipmentLocationRightFoot) + return true; + else + return false; + } } } \ No newline at end of file Modified: src/RPGWorldModel.Abstracts/Humanoid.cs =================================================================== --- src/RPGWorldModel.Abstracts/Humanoid.cs 2006-07-12 17:52:16 UTC (rev 14) +++ src/RPGWorldModel.Abstracts/Humanoid.cs 2006-07-14 16:42:36 UTC (rev 15) @@ -41,59 +41,102 @@ } #endregion - - + + public override EquipResponse Equip(EquipRequest request) { EquipResponse response = new EquipResponse(); - response.Status = EquipStatus.NotEquippedNotAbleToEquip; + response.Status = EquipStatus.Undefined; + response.AffectedSlot = null; + if (!equipmentSlots.Contains(request.RequestedSlot)) + { + response.Status = EquipStatus.NotEquippedSlotNotPartOfEntity; + response.AffectedSlot = request.RequestedSlot; + return response; + } - // Basic equip implementation for humanoids - foreach (EquipmentSlot slot in AvailableEquipmentSlots) + // Iterating over locations from equipable and trying to match them if open slots + + EquipmentSlotList selectedSlots = new EquipmentSlotList(); + bool initialSlotAccepting = false; + + foreach (EquipmentLocationDescriptor locationDescriptor in + request.RequestedEquipable.EquipmentLocationDescriptors) { - // Checking is slot is part of entity - if (slot == request.RequestedSlot) + initialSlotAccepting = false; + + // Checking if initial slot accepts any of the location + foreach (EquipmentLocation location in locationDescriptor.EquipmentLocations) + if (request.RequestedSlot.IsLocationAcceptable(location)) + { + initialSlotAccepting = true; + break; + } + + if (!initialSlotAccepting) { - // Checking is slot can accept any of the equipe locations for equipable + if (response.Status == EquipStatus.Undefined) + { + response.Status = EquipStatus.NotEquippedNotAbleToEquipToSlot; + response.AffectedSlot = request.RequestedSlot; + } - foreach (EquipmentLocationDescriptor locationDescriptor - in request.RequestedEquipable.EquipmentLocationDescriptors) + continue; + } + + // Initial is accepting, check other + selectedSlots.Clear(); + + foreach (EquipmentLocation location in locationDescriptor.EquipmentLocations) + { + foreach (EquipmentSlot slot in equipmentSlots) { - // TODO: multi-slot items support - if (locationDescriptor.EquipmentLocationsCount > 1) + // Can slot accept equipable + if (slot.IsLocationAcceptable(location)) { - break; + selectedSlots.Add(slot); + break; //NO OTHER LOCATION CAN ACCEPT } + } + } - if (locationDescriptor.EquipmentLocationsCount == 0) + if (selectedSlots.Count == locationDescriptor.EquipmentLocationsCount) + { + // Checking capacity + foreach (EquipmentSlot slot in selectedSlots) + { + // TEMP + if (slot.EquippedEntitiesCount > 0) { - break; //TODO : error + response.Status = EquipStatus.NotEquippedNoCapacityLeftInSlot; + response.AffectedSlot = slot; + break; } + } - if (locationDescriptor.EquipmentLocationsCount == 1) - { - foreach (EquipmentLocation location in locationDescriptor.EquipmentLocations) - if (slot.IsLocationAcceptable(location)) - { - slot.AddEquipable(request.RequestedEquipable); - response.Status = EquipStatus.Equipped; - break; - } - } + if (response.Status != EquipStatus.NotEquippedNoCapacityLeftInSlot) + { + // OK + response.Status = EquipStatus.Equipped; + response.AffectedSlot = request.RequestedSlot; - if (response.Status == EquipStatus.Equipped) - break; - + foreach (EquipmentSlot slot in selectedSlots) + slot.AddEquipable(request.RequestedEquipable); + + break; } - if (response.Status == EquipStatus.Equipped) - break; } + else + { + response.Status = EquipStatus.NotEquippedNotAbleToEquipToAdditionalSlots; + response.AffectedSlot = null; + } } - + return response; } Modified: src/RPGWorldModel.Abstracts/IEquip.cs =================================================================== --- src/RPGWorldModel.Abstracts/IEquip.cs 2006-07-12 17:52:16 UTC (rev 14) +++ src/RPGWorldModel.Abstracts/IEquip.cs 2006-07-14 16:42:36 UTC (rev 15) @@ -49,14 +49,25 @@ get { return status; } set { status = value; } } + + private EquipmentSlot affectedSlot = null; + + public EquipmentSlot AffectedSlot + { + get { return affectedSlot; } + set { affectedSlot = value; } + } } public enum EquipStatus { Undefined, Equipped, - NotEquippedNotAbleToEquip, + NotEquippedNotAbleToEquipToSlot, NotEquippedConflictingWithAlreadyEquippedEntity, NotEquippedNotAbleToEquipAnyEntities, // If and entity is not able to equipe any entities (e.g. animals) + NotEquippedNoCapacityLeftInSlot, + NotEquippedSlotNotPartOfEntity, + NotEquippedNotAbleToEquipToAdditionalSlots } } Modified: src/RPGWorldModel.Abstracts/Sword.cs =================================================================== --- src/RPGWorldModel.Abstracts/Sword.cs 2006-07-12 17:52:16 UTC (rev 14) +++ src/RPGWorldModel.Abstracts/Sword.cs 2006-07-14 16:42:36 UTC (rev 15) @@ -28,8 +28,8 @@ { if (!durability.IsInitialized) { - durability.BaseDurability = 1000; - durability.DurabilityMargin = 15; + durability.BaseDurability = 0; + durability.DurabilityMargin = 0; durability.IsInitialized = true; durability.RandomizationRequired = true; } @@ -47,10 +47,10 @@ { if (!damageDescriptor.IsInitialized && damageDescriptor is DamageDescriptorPhysical) { - damageDescriptor.BaseMinDamage = 30; - damageDescriptor.MinDamageMargin = 5; - damageDescriptor.BaseMaxDamage = 35; - damageDescriptor.MaxDamageMargin = 10; + damageDescriptor.BaseMinDamage = 0; + damageDescriptor.MinDamageMargin = 0; + damageDescriptor.BaseMaxDamage = 0; + damageDescriptor.MaxDamageMargin = 0; damageDescriptor.IsInitialized = true; damageDescriptor.RandomizationRequired = true; } @@ -83,4 +83,68 @@ } #endregion } + + public class TwoHandedSword : Sword + { + public TwoHandedSword() + { + } + + #region Initialization Overrides + + public override void InitializeNamedEntity() + { + if (!name.IsInitialized) + { + name.Value = "Two-Handed Sword"; + name.IsInitialized = true; + } + } + + public override void InitializeDamagable() + { + if (!durability.IsInitialized) + { + durability.BaseDurability = 0; + durability.DurabilityMargin = 0; + durability.IsInitialized = true; + durability.RandomizationRequired = true; + } + + if (durability.RandomizationRequired) + randomizeMaxDurability(); + } + + public override void InitializeDamageInflictor() + { + DamageDescriptorPhysical damageDesc = new DamageDescriptorPhysical(); + damageDesc.BaseMaxDamage = 0; + damageDesc.MaxDamageMargin = 0; + damageDesc.BaseMinDamage = 0; + damageDesc.MinDamageMargin = 0; + damageDesc.IsInitialized = true; + damageDesc.RandomizationRequired = true; + + addDamageDescriptorIfNotExisting(damageDesc); + + base.InitializeDamageInflictor(); + } + + public override void InitializeEquipable() + { + equipmentLocationDescriptors.Clear(); + + // Building descriptors + EquipmentLocationDescriptor bothHands = new EquipmentLocationDescriptor(); + bothHands.AddEquipmentLocation(new EquipmentLocationLeftHand()); + bothHands.AddEquipmentLocation(new EquipmentLocationRightHand()); + equipmentLocationDescriptors.Add(bothHands); + + EquipmentLocationDescriptor back = new EquipmentLocationDescriptor(); + back.AddEquipmentLocation(new EquipmentLocationBack()); + equipmentLocationDescriptors.Add(back); + } + #endregion + } + } Modified: src/RPGWorldModel.Implementation/Swords.cs =================================================================== --- src/RPGWorldModel.Implementation/Swords.cs 2006-07-12 17:52:16 UTC (rev 14) +++ src/RPGWorldModel.Implementation/Swords.cs 2006-07-14 16:42:36 UTC (rev 15) @@ -76,4 +76,41 @@ #endregion } + + + /// <summary> + /// Bronze Two-Handed Sword + /// </summary> + public class BronzeTwoHandedSword : TwoHandedSword + { + public BronzeTwoHandedSword() + { + name.Value = "Bronze Two-Handed Sword"; + name.IsInitialized = true; + + durability.BaseDurability = 2000; + durability.DurabilityMargin = 20; + durability.IsInitialized = true; + durability.RandomizationRequired = true; + } + + #region Initialization Overrides + + public override void InitializeDamageInflictor() + { + DamageDescriptorPhysical damageDesc = new DamageDescriptorPhysical(); + damageDesc.BaseMaxDamage = 40; + damageDesc.MaxDamageMargin = 10; + damageDesc.BaseMinDamage = 5; + damageDesc.MinDamageMargin = 10; + damageDesc.IsInitialized = true; + damageDesc.RandomizationRequired = true; + + addDamageDescriptorIfNotExisting(damageDesc); + + base.InitializeDamageInflictor(); + } + + #endregion + } } \ No newline at end of file Modified: src/test_applications/tester/Form1.Designer.cs =================================================================== --- src/test_applications/tester/Form1.Designer.cs 2006-07-12 17:52:16 UTC (rev 14) +++ src/test_applications/tester/Form1.Designer.cs 2006-07-14 16:42:36 UTC (rev 15) @@ -380,6 +380,7 @@ // this.lvAvailableItems.HideSelection = false; this.lvAvailableItems.Location = new System.Drawing.Point(319, 176); + this.lvAvailableItems.MultiSelect = false; this.lvAvailableItems.Name = "lvAvailableItems"; this.lvAvailableItems.Size = new System.Drawing.Size(322, 97); this.lvAvailableItems.TabIndex = 3; Modified: src/test_applications/tester/Form1.cs =================================================================== --- src/test_applications/tester/Form1.cs 2006-07-12 17:52:16 UTC (rev 14) +++ src/test_applications/tester/Form1.cs 2006-07-14 16:42:36 UTC (rev 15) @@ -312,17 +312,32 @@ { if (equipable is Sword) { - g.FillRectangle(Brushes.Blue, x, y, 5, 100); - g.FillRectangle(Brushes.Blue, x - 10, y + 20, 25, 5); + int swordLength = 100; + Brush selectedBrush = Brushes.Gray; + + if (equipable is WoodenTrainingSword) + { + selectedBrush = Brushes.Brown; + swordLength = 80; + } + + if (equipable is BronzeTwoHandedSword) + { + selectedBrush = Brushes.DarkRed; + swordLength = 140; + } + + g.FillRectangle(selectedBrush, x, y, 5, swordLength); + g.FillRectangle(selectedBrush, x - 10, y + 20, 25, 5); Point[] points = new Point[3]; points[0].X = x; - points[0].Y = y + 100; + points[0].Y = y + swordLength; points[1].X = x + 2; - points[1].Y = y + 110; + points[1].Y = y + swordLength + 10; points[2].X = x+5; - points[2].Y = y + 100; - g.FillPolygon(Brushes.Blue, points); + points[2].Y = y + swordLength; + g.FillPolygon(selectedBrush, points); } } @@ -369,14 +384,20 @@ equipTest = new Human(); equipTest.InitializeEntity(); + availableEquipable.Clear(); + IronShortSword sword = new IronShortSword(); sword.InitializeEntity(); WoodenTrainingSword wSword = new WoodenTrainingSword(); wSword.InitializeEntity(); + BronzeTwoHandedSword bthSword = new BronzeTwoHandedSword(); + bthSword.InitializeEntity(); + availableEquipable.Add(sword); availableEquipable.Add(wSword); + availableEquipable.Add(bthSword); refreshEquip(); } @@ -433,6 +454,21 @@ if (response.Status == EquipStatus.Equipped) availableEquipable.Remove(selectedEquipable); + if (response.Status == EquipStatus.NotEquippedNoCapacityLeftInSlot) + { + MessageBox.Show("You cannot put more items into " + (response.AffectedSlot != null ? response.AffectedSlot.SlotName : "UNKNOWN")); + } + + if (response.Status == EquipStatus.NotEquippedNotAbleToEquipToSlot) + { + MessageBox.Show("You cannot put " + (selectedEquipable as INamedEntity).Name + " into " + (response.AffectedSlot != null ? response.AffectedSlot.SlotName : "UNKNOWN")); + } + + if (response.Status == EquipStatus.NotEquippedNotAbleToEquipToAdditionalSlots) + { + MessageBox.Show("You cannot put " + (selectedEquipable as INamedEntity).Name + " becuase of lack of capacity in other slots"); + } + refreshEquip(); } } Modified: src/test_applications/tester/tester.csproj =================================================================== --- src/test_applications/tester/tester.csproj 2006-07-12 17:52:16 UTC (rev 14) +++ src/test_applications/tester/tester.csproj 2006-07-14 16:42:36 UTC (rev 15) @@ -18,6 +18,7 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <UseVSHostingProcess>false</UseVSHostingProcess> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |