public virtual float GetNetDamage(Dynamic target) { float RD = (ActiveHeldItem as MultipleActionItem).GetDamage(); //= random damage value produced from weapons hit damage range float RB = 0; //= ranged bonus (RB=0 unless the player has Bonus Ranged Damage perk) float CM = 2; //= critical hit damage multiplier (if no critical hit then CM=2, otherwise assigned value from critical hit table) float ADR = 0; // armor damage resistance value float ADT = 0; // armor damage threshold value float X = 0; float Y = 0; float RM = 0; // = ammo resistance modifier (only value allowed to be negative or positive in the equation) float CD = 75; // = combat difficulty multiplier (Easy=75, Normal=100, Hard=125) VBWeaponItem wpn = ActiveHeldItem as VBWeaponItem; if (wpn != null && wpn.AmmoTypeLoaded != null) { RM = wpn.AmmoTypeLoaded.DmgResistance; X = wpn.AmmoTypeLoaded.DmgModifier.Minimum; // = ammo dividend Y = wpn.AmmoTypeLoaded.DmgModifier.Maximum; // = ammo dividend } /*/his armor, not mine! * RTSCharacter opponent = target as RTSCharacter; * if (opponent != null && opponent.armor != null) * { * ADR = opponent.armor.Type.Resistance; * ADT = opponent.armor.Type.Threshold; * }*/ return((((RD + RB) * (X * CM) / Y / 2.0f * CD / 100.0f) - ADT) * ((100.0f - (ADR + RM)) / 100.0f)); }
public virtual bool TakeItem(VBItem i) { if (!CanHoldItem(i.Type)) { return(false); } bool shouldAdd = true; //is it ammo and i already have one? if (i.Type as AmmoItemType != null) { InventoryObjectItem existing = Inventory.Find(search => search.ItemType == i.Type); if (existing != null) { existing.Juice += (i as AmmoItem).Juice; shouldAdd = false; } } if (shouldAdd) { InventoryObjectItem tmp = new InventoryObjectItem(); tmp.SetType(i.Type); ConsumableItem ctmp = i as ConsumableItem; if (ctmp != null) { tmp.SetJuice(ctmp.Juice); if (ctmp.Juice > 0) { VBWeaponItem wtmp = ctmp as VBWeaponItem; if (wtmp != null) { tmp.AmmoType = wtmp.AmmoTypeLoaded; } } } Inventory.Add(tmp); } i.SetForDeletion(false); return(true); }
public InventoryObjectItem SetBestWeapon() { foreach (InventoryObjectItem i in Inventory) { if ((i.ItemType as VBWeaponItemType) != null) { SetItem(i, true); //try a reload VBWeaponItem itm = ActiveHeldItem as VBWeaponItem; if (itm != null) { itm.TryReload(); } return(i); } } return(null); }
protected virtual void TickTasks() { RTSUnit controlledObj = ControlledObject; if (controlledObj == null) { return; } switch (currentTask.Type) { //Stop case Task.Types.Stop: controlledObj.Stop(); break; //Move case Task.Types.Move: case Task.Types.BreakableMove: if (currentTask.Entity != null) { controlledObj.Move(currentTask.Entity.Position); } else { Vec3 pos = currentTask.Position; if ((controlledObj.Position.ToVec2() - pos.ToVec2()).Length() < 1.5f && Math.Abs(controlledObj.Position.Z - pos.Z) < 3.0f) { //get to DoNextTask(); } else { controlledObj.Move(pos); } } break; //Reload case Task.Types.Reload: VBWeaponItem wpn = (controlledObj as VBCharacter).ActiveHeldItem as VBWeaponItem; if (wpn != null) { wpn.TryReload(); DoNextTask(); } break; //Pickup case Task.Types.PickUp: if (InTaskRange()) { if (currentTask.Entity as VBItem != null) { (controlledObj as VBCharacter).TakeItem(currentTask.Entity as VBItem); } DoNextTask(); } break; //Use case Task.Types.Use: if (InTaskRange()) { InteractableObject itm = currentTask.Entity as InteractableObject; if (itm != null) { itm.Interact(controlledObj); } DoNextTask(); } break; //Talk case Task.Types.Talk: if (InTaskRange()) { EngineConsole.Instance.ExecuteString("createWindow chat"); DoNextTask(); } break; //preuse case Task.Types.PreUse: break; //Attack, Repair case Task.Types.Attack: case Task.Types.BreakableAttack: //case Task.Types.Repair: //case Task.Types.BreakableRepair: { /*/healed * if( ( currentTask.Type == Task.Types.Repair || * currentTask.Type == Task.Types.BreakableRepair ) * && currentTask.Entity != null ) * { * if( currentTask.Entity.Health == currentTask.Entity.Type.HealthMax ) * { * DoNextTask(); * break; * } * }*/ float needDistance = controlledObj.Type.OptimalAttackDistanceRange.Maximum; MultipleActionItem itm = (controlledObj as VBCharacter).ActiveHeldItem as MultipleActionItem; if (itm != null) { needDistance = itm.GetCurActionMode().UseDistanceRange.Maximum; } Vec3 targetPos; if (currentTask.Entity != null) { targetPos = currentTask.Entity.Position; } else { targetPos = currentTask.Position; } float distance = (controlledObj.Position - targetPos).Length(); if (distance != 0) { bool lineVisibility = false; { if (distance < needDistance) { lineVisibility = true; //direct line visibility check Vec3 start = ControlledObject.Position; Ray ray = new Ray(start, targetPos - start); RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray, (int)ContactGroup.CastOnlyContact); foreach (RayCastResult result in piercingResult) { MapObject obj = MapSystemWorld.GetMapObjectByBody(result.Shape.Body); if (obj != null && obj == currentTask.Entity) { break; } if (obj != controlledObj) { lineVisibility = false; break; } } } } //movement control if (lineVisibility) { //stop controlledObj.Stop(); RTSCharacter character = controlledObj as RTSCharacter; if (character != null) { character.SetLookDirection(targetPos); } } else { //move to target controlledObj.Move(targetPos); } //weapons control if (lineVisibility) { (ControlledObject as VBCharacter).BaseAttack(currentTask.Entity, null); DoNextTask(); /* * foreach( Weapon weapon in initialWeapons ) * { * Vec3 pos = targetPos; * Gun gun = weapon as Gun; * if( gun != null && currentTask.Entity != null ) * gun.GetAdvanceAttackTargetPosition( false, currentTask.Entity, false, out pos ); * weapon.SetForceFireRotationLookTo( pos ); * * if( weapon.Ready ) * { * Range range; * * range = weapon.Type.WeaponNormalMode.UseDistanceRange; * if( distance >= range.Minimum && distance <= range.Maximum ) * weapon.TryFire( false ); * * range = weapon.Type.WeaponAlternativeMode.UseDistanceRange; * if( distance >= range.Minimum && distance <= range.Maximum ) * weapon.TryFire( true ); * } * }*/ } } } break; } }
public virtual void UpdateCurrentItem() { if (EntitySystemWorld.Instance.WorldSimulationType == WorldSimulationTypes.Editor) { return; } //handle my current object if any if (activeHeldItem != null) { if (activeHeldItemAttachedObject != null) { Detach(activeHeldItemAttachedObject); activeHeldItemAttachedObject = null; } activeHeldItem.SetForDeletion(false); activeHeldItem = null; /* TODO: ONLINE ITEM SUPPORT - TO DO WHEN PORTING * if (EntitySystemWorld.Instance.IsServer()) * Server_SendSetactiveHeldItemToClients(EntitySystemWorld.Instance.RemoteEntityWorlds);*/ } if (GetCurItem != null) { CreateActiveItem(GetCurItem.ItemType.Name); //activeHeldItem.Server_EnableSynchronizationPositionsToClients = false; //transfer the info from the itm to the newly created gun ConsumableItem consItm = activeHeldItem as ConsumableItem; if (consItm != null) { consItm.Juice = GetCurItem.Juice; consItm.ActionMode = GetCurItem.ActionMode; VBWeaponItem wpnItm = consItm as VBWeaponItem; if (wpnItm != null) { wpnItm.AmmoTypeLoaded = GetCurItem.AmmoType; } } //TODO: PREVENT THE OBJECT ATTACHMENT BUG //CreateactiveHeldItemAttachedObject(); /* ONLINE ITEM SUPPORT - TO DO WHEN PORTING * if (EntitySystemWorld.Instance.IsServer()) * Server_SendSetactiveHeldItemToClients(EntitySystemWorld.Instance.RemoteEntityWorlds);*/ } else { if (Type.MeleeAttacks != null) { if (primaryActive) { CreateActiveItem(Type.MeleeAttacks[0]); } else { CreateActiveItem(Type.MeleeAttacks[1]); } } } }