/// <summary> /// 加载主武器(子类重写该方法可加特效) /// </summary> public virtual void LoadPrimaryWeapon() { //错误检测 if (weaponBottom == null) { Debug.LogError("必须先有底座才能加载主武器!"); return; } //若已存在则延时删除 GameObject toDestroy = null; if (primaryWeapon != null) { toDestroy = primaryWeapon.gameObject; } //加载 primaryWeapon = GameObject.Instantiate(GameSystem.WeaponSystem.getPrefab(primaryWeaponEnum), weaponBottom.primaryWeaponPosition).GetComponent <PrimaryWeapon>(); primaryWeapon.AttachICP(this); if (secondaryWeapon != null) { secondaryWeapon.SetPosition(primaryWeapon.secondaryWeaponPositionL, primaryWeapon.secondaryWeaponPositionR); } //删除 if (toDestroy != null) { DestroyImmediate(toDestroy); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // /// </summary> protected override void SightLineCheck() { // Look at attack target _IsAttacking = true; ///if (_IsAttacking) { LookAt(_AttackTargetObject.transform.position); } // Fire raycast to confirm valid line of sight to target int def = 1 << LayerMask.NameToLayer("Default"); int units = 1 << LayerMask.NameToLayer("Units"); LayerMask mask = def | units; RaycastHit hit; if (Physics.Raycast(MuzzleLaunchPoints[0].transform.position, WeaponObject.transform.forward, out hit, MaxAttackingRange, mask)) { // There is a line of sight to the target, fire the weapon (if possible) if (PrimaryWeapon.CanFire()) { PrimaryWeapon.FireWeapon(); } Debug.DrawRay(MuzzleLaunchPoints[0].transform.position, WeaponObject.transform.forward * MaxAttackingRange, Color.green); } else { Debug.DrawRay(MuzzleLaunchPoints[0].transform.position, WeaponObject.transform.forward * MaxAttackingRange, Color.red); } }
public void UpdateWeaponState(PlayerInput.Input input) { PrimaryWeapon.UpdateState(); if (input.Shoot) { PrimaryWeapon.TryFire(); } else { PrimaryWeapon._isTriggerReleased = true; } if (input.Aim) { PrimaryWeapon.Aim(); } else if (input.Reload) { PrimaryWeapon.BeginReload(); } else if (input.Melee) { //Melee(); } if (input.Shift) { ChangeWeapons(); } }
protected override void UpdateInternal(GameTime time) { Body.SleepingAllowed = false; UnsafeDisableEvents(); var velocity = InputState.MovementSpeed * MovementSpeed; var rotationAmount = InputState.RotationSpeed * RotationSpeed * (time.ElapsedGameTime.TotalMilliseconds / 16.66666); //calculate the actual movement by axis var x = velocity * Math.Sin(Rotation); var y = velocity * -Math.Cos(Rotation); LinearVelocity = new Vector2((float)x, (float)y); AngularVelocity = 0; Rotation += (float)rotationAmount; UnsafeEnableEvents(); //Set the active weapon SetActiveWeapon(); //And update weapons PrimaryWeapon?.Update(time); SecondaryWeapon?.Update(time); TertiaryWeapon?.Update(time); if (ActiveWeapon.Recharged && InputState.FirePressed) { ActiveWeapon.Fire(); } }
public bool Melee(Character target) { if (target.GodMode) { return(true); } if (PrimaryWeapon != null) { if (PrimaryWeapon.TryUse(Context, target)) { return(true); } } foreach (var meta in Meta.Abilities) { if (meta is IAbility ability) { if (ability.CanUse(Context)) { ability.Use(Context, target); } } } return(true); }
public void ToStream(XmlWriter s, Managers.TagManager tag, TI.Definition owner) { s.WriteStartElement("entry"); s.WriteAttributeString("name", Name.ToString()); if (!AppSlot1.Handle.IsNull) { s.WriteAttributeString("appSlot1", AppSlot1.ToString()); } if (!AppSlot2.Handle.IsNull) { s.WriteAttributeString("appSlot2", AppSlot2.ToString()); } if (!PrimaryWeapon.Handle.IsNull) { s.WriteAttributeString("primary", PrimaryWeapon.ToString()); } if (!SecondaryWeapon.Handle.IsNull) { s.WriteAttributeString("secondary", SecondaryWeapon.ToString()); } if (!Equipment.Handle.IsNull) { s.WriteAttributeString("equipment", Equipment.ToString()); } s.WriteEndElement(); }
/// <summary> /// Kills the player /// </summary> public void Kill() { Health = 0; Armor = 0; State = ServerClientInterface.PlayerState.Dead; PrimaryWeapon.Drop(); }
protected override void GetTypeStateHeader(ByteArrayWriter writer) { writer.Write(PrimaryWeapon != null); PrimaryWeapon?.GetFullState(writer); writer.Write(SecondaryWeapon != null); SecondaryWeapon?.GetFullState(writer); writer.Write(TertiaryWeapon != null); TertiaryWeapon?.GetFullState(writer); }
public Player(string Name, int Health, int Mana, PrimaryWeapon EquippedWeapon, SecondaryWeapon equippedSecondaryWeapon, Item EquippedItem, Inventory Inventory) { name = Name; health = Health; mana = Mana; equippedPrimaryWeapon = EquippedWeapon; equippedItem = EquippedItem; inventory = Inventory; }
private void SetUpStats() { player = FindObjectOfType <Player>(); myCurrentHealth = player.GetHealth(); primaryWeapon = FindObjectOfType <PrimaryWeapon>(); currentFireRate = primaryWeapon.GetFireRate(); damage = FindObjectOfType <DamageDealer>(); currentDamage = damage.GetDamage(); }
/// <summary> /// Recalculates the position of the player fields. /// </summary> public void Recalculate() { float x = GGO.menu.PlayerX.SelectedItem; float y = GGO.menu.PlayerY.SelectedItem; PointF position = new PointF(1f.ToXAbsolute() + x, 1080 + y); Health.Recalculate(position); PrimaryWeapon.Recalculate(new PointF(position.X, position.Y + 50 + 5)); SecondaryWeapon.Recalculate(new PointF(position.X, position.Y + (50 * 2) + (5 * 2))); }
public override void FireSecondary() { if (!GetOverheat()) { SecondaryWeapon.Fire(); PrimaryWeapon.Fire(); PrimaryWeapon.SetFireRate(PFireRate * (((GetHeat() / GetMaxHeat()) + 1)) * 10); SecondaryWeapon.SetFireRate(PFireRate * (((GetHeat() / GetMaxHeat()) + 1)) * 10); } }
// Self-initialize. private void Awake() { // Set the active weapon slot. ActiveWeaponSlot = WeaponSlot.Primary; // Equip a pistol. PrimaryWeapon = Instantiate(pistolTemplate).GetComponent <Pistol>(); PrimaryWeapon.Initialize(transform, this); // Start facing down. Towards the camera. Direction = Vector3.down; }
// Update. private void Update() { float x = Input.GetAxis("Horizontal"); float y = Input.GetAxis("Vertical"); // Update direction. float absX = Mathf.Abs(x); float absY = Mathf.Abs(y); if (absX >= absY) { if (x < 0) { // Face left. Direction = Vector3.left; } else if (x > 0) { // Face right. Direction = Vector3.right; } } else if (absY > absX) { if (y < 0) { // Face down. Direction = Vector3.down; } else if (y > 0) { // Face up. Direction = Vector3.up; } } if (Input.GetButtonDown("Fire1")) { switch (ActiveWeaponSlot) { case WeaponSlot.Primary: PrimaryWeapon.Use(); break; case WeaponSlot.Secondary: break; } } }
protected override void SetTypeStateHeader(ByteArrayReader reader) { if (reader.ReadBool() && PrimaryWeapon != null) { PrimaryWeapon.SetFullState(reader); } if (reader.ReadBool() && SecondaryWeapon != null) { SecondaryWeapon.SetFullState(reader); } if (reader.ReadBool() && TertiaryWeapon != null) { TertiaryWeapon.SetFullState(reader); } }
private void ChangeWeapons() { int p = _primary; _primary = _secondary; _secondary = p; SecondaryWeapon.Dequipped(); SecondaryWeapon.gameObject.SetActive(false); PrimaryWeapon.gameObject.SetActive(true); PrimaryWeapon.Equipped(); BroadcastWeaponChanged(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called every frame - updates the soldier/unit's movement and combat behaviours. /// </summary> protected override void UpdateAIControllerMovement() { base.UpdateAIControllerMovement(); // Follow our healing target if (_HealingTarget != null) { _AttackTarget = _HealingTarget; // Close the gap if were too far away from our target float dist = Vector3.Distance(transform.position, _HealingTarget.transform.position); if (dist > HangingDistance) { // Just go to our targets position, this will update again if they get too far anyway AgentSeekPosition(_HealingTarget.transform.position, false, false); } // Check if the target is within attacking range _DistanceToTarget = Vector3.Distance(transform.position, _HealingTarget.transform.position); if (_DistanceToTarget <= MaxAttackingRange && PrimaryWeapon != null) { // Make the muzzle point face the healing target MuzzleLaunchPoints[0].transform.LookAt(_HealingTarget.transform); // Heal the target if (PrimaryWeapon.CanFire()) { OnFireWeapon(); } } // Healing target does not become target if it has full health or is dead if (!_HealingTarget.IsAlive() || (_HealingTarget.GetHealth() >= 1f) || _HealingTarget.GetHitPoints() >= _HealingTarget.MaxHitPoints) { _HealingTarget = null; } } // No healing target, means no attack target else { _AttackTarget = null; } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // /// </summary> protected override void UpdatePlayerControlledMovement() { // Directional movement with WASD ///Vector3 inputDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); ///transform.SetPositionAndRotation(transform.position + inputDirection * (InfantryMovementSpeed * Time.deltaTime), transform.rotation); // Forward input float forward = Input.GetAxis("Vertical"); if (forward != 0f) { transform.position = transform.position + transform.forward * forward * InfantryMovementSpeed * Time.deltaTime; } // Right input float right = Input.GetAxis("Horizontal"); if (right != 0f) { transform.position = transform.position + transform.right * right * InfantryMovementSpeed * Time.deltaTime; } // Update base rotation _ControlRotation = Input.GetAxis("Mouse X") * RotatingSpeed * Time.deltaTime; if (_ControlRotation != 0) { transform.eulerAngles += new Vector3(0f, _ControlRotation, 0f); } // Check for weapon firing input if (Input.GetMouseButtonDown(0)) { // If theres a weapon attached if (PrimaryWeapon) { // Fire the weapon if possible if (PrimaryWeapon.CanFire()) { PrimaryWeapon.FireWeapon(); } } } }
public void UnRegisterPrimaryWeapon(PrimaryWeapon primaryWeapon) { this.primaryWeapon = null; primaryWeapon.owner = null; primaryWeapon.transform.parent = null; OnStartFiringListeners -= primaryWeapon.OnStartFiring; OnStopFiringListeners -= primaryWeapon.OnStopFiring; foreach (var weapon in primaryWeapon.weaponSlots.SelectMany(slot => slot.weapons)) { if (weapon.energyConsumer.IsUnused == false) { energyConsumers.Remove(weapon.energyConsumer); } } primaryWeapon.gameObject.SetActive(false); }
public void RegisterPrimaryWeapon(PrimaryWeapon primaryWeapon) { this.primaryWeapon = primaryWeapon; weaponRegistered = true; transform.AdoptChild(primaryWeapon.transform); primaryWeapon.owner = this; OnStartFiringListeners += primaryWeapon.OnStartFiring; OnStopFiringListeners += primaryWeapon.OnStopFiring; foreach (var weapon in primaryWeapon.weaponSlots.SelectMany(slot => slot.weapons)) { if (weapon.energyConsumer.IsUnused == false) { energyConsumers.Add(weapon.energyConsumer); } } primaryWeapon.gameObject.SetActive(true); }
private void Awake() { input = GetComponent <ShipInput>(); weapon = GetComponent <PrimaryWeapon>(); }
private void SelectPrimaryWeapon(PlayerInput input, PrimaryWeapon weapon, bool silent = false) { if (weapon == selectedPrimaryWeapon) { //Debug.LogFormat("Primary weapon '{0}' already selected.", weapon); return; } if (selectedLeftPrimaryWeapon != null) selectedLeftPrimaryWeapon.OnDeselect(); if (selectedRightPrimaryWeapon != null) selectedRightPrimaryWeapon.OnDeselect(); switch (weapon) { case PrimaryWeapon.None: selectedLeftPrimaryWeapon = null; selectedRightPrimaryWeapon = null; rightWeaponIndicatorIcon.enabled = false; rightWeaponIndicatorNoneIcon.enabled = true; rightWeaponIndicatorInfiniteIcon.enabled = false; rightWeaponIndicatorAmmoLabel.enabled = false; break; case PrimaryWeapon.PlasmaGun: selectedLeftPrimaryWeapon = leftPlasmaGun; selectedRightPrimaryWeapon = rightPlasmaGun; rightWeaponIndicatorIcon.sprite = plasmaGunIcon; rightWeaponIndicatorIcon.enabled = true; rightWeaponIndicatorNoneIcon.enabled = false; rightWeaponIndicatorInfiniteIcon.enabled = true; rightWeaponIndicatorAmmoLabel.enabled = false; break; case PrimaryWeapon.Laser: selectedLeftPrimaryWeapon = leftLaser; selectedRightPrimaryWeapon = rightLaser; rightWeaponIndicatorIcon.sprite = laserIcon; rightWeaponIndicatorIcon.enabled = true; rightWeaponIndicatorNoneIcon.enabled = false; rightWeaponIndicatorInfiniteIcon.enabled = false; rightWeaponIndicatorAmmoLabel.enabled = true; break; default: throw new Exception("Unexpected PrimaryWeapon."); } if (selectedLeftPrimaryWeapon != null) selectedLeftPrimaryWeapon.OnSelect(input); if (selectedRightPrimaryWeapon != null) selectedRightPrimaryWeapon.OnSelect(input); selectedPrimaryWeapon = weapon; }
private void SelectPrimaryWeapon(PlayerInput input, PrimaryWeapon weapon, bool silent = false) { if (weapon == selectedPrimaryWeapon) { //Debug.LogFormat("Primary weapon '{0}' already selected.", weapon); return; } if (selectedLeftPrimaryWeapon != null) { selectedLeftPrimaryWeapon.OnDeselect(); } if (selectedRightPrimaryWeapon != null) { selectedRightPrimaryWeapon.OnDeselect(); } switch (weapon) { case PrimaryWeapon.None: selectedLeftPrimaryWeapon = null; selectedRightPrimaryWeapon = null; rightWeaponIndicatorIcon.enabled = false; rightWeaponIndicatorNoneIcon.enabled = true; rightWeaponIndicatorInfiniteIcon.enabled = false; rightWeaponIndicatorAmmoLabel.enabled = false; break; case PrimaryWeapon.PlasmaGun: selectedLeftPrimaryWeapon = leftPlasmaGun; selectedRightPrimaryWeapon = rightPlasmaGun; rightWeaponIndicatorIcon.sprite = plasmaGunIcon; rightWeaponIndicatorIcon.enabled = true; rightWeaponIndicatorNoneIcon.enabled = false; rightWeaponIndicatorInfiniteIcon.enabled = true; rightWeaponIndicatorAmmoLabel.enabled = false; break; case PrimaryWeapon.Laser: selectedLeftPrimaryWeapon = leftLaser; selectedRightPrimaryWeapon = rightLaser; rightWeaponIndicatorIcon.sprite = laserIcon; rightWeaponIndicatorIcon.enabled = true; rightWeaponIndicatorNoneIcon.enabled = false; rightWeaponIndicatorInfiniteIcon.enabled = false; rightWeaponIndicatorAmmoLabel.enabled = true; break; default: throw new Exception("Unexpected PrimaryWeapon."); } if (selectedLeftPrimaryWeapon != null) { selectedLeftPrimaryWeapon.OnSelect(input); } if (selectedRightPrimaryWeapon != null) { selectedRightPrimaryWeapon.OnSelect(input); } selectedPrimaryWeapon = weapon; }
public override void Observe(string eventMessage, object thing) { PrimaryWeaponDisplay = (PrimaryWeapon)thing; }
public void Update() { PrimaryWeaponDisplay = null; Messages.Update(); }
private void WeaponPreAttack(RoundResult rr) { PrimaryWeapon.PreAttack(this, rr); SecondaryWeapon.PreAttack(this, rr); }
// Start is called before the first frame update void Start() { //player = FindObjectOfType<Player>(); fireRateText = GetComponent <Text>(); primaryWeapon = FindObjectOfType <PrimaryWeapon>(); }
public void UpdatePlayerWeapons(GameTime gameTime) { // Waffenaiming if (PrimaryWeapon != null) { PrimaryWeapon.AimAt(); } if (SecondaryWeapon != null) { SecondaryWeapon.AimAt(); } // End Fire foreach (KeyValuePair <WeaponType, IWeapon> pair in weapons) { if (pair.Value != PrimaryWeapon && pair.Value != SecondaryWeapon && pair.Key != WeaponType.NO_WEAPON) { pair.Value.EndFire(); } } // Waffenfeuer if (game.Input.IsKeyDown("Player1.PrimaryFire")) { if (PrimaryWeapon != null) { PrimaryWeapon.BeginFire(); } } else { if (PrimaryWeapon != null) { PrimaryWeapon.EndFire(); } } if (game.Input.IsKeyDown("Player1.SecondaryFire")) { if (SecondaryWeapon != null) { SecondaryWeapon.BeginFire(); } } else { if (SecondaryWeapon != null) { SecondaryWeapon.EndFire(); } } // Waffenwechsel if (game.Input.HasKeyJustBeenPressed("Player1.PrimaryWeapon.Select1")) { SetPrimaryWeapon(WeaponType.ULTRA_PHASER); } if (game.Input.HasKeyJustBeenPressed("Player1.PrimaryWeapon.Select2")) { SetPrimaryWeapon(WeaponType.MINIGUN); } if (game.Input.HasKeyJustBeenPressed("Player1.PrimaryWeapon.Select3")) { SetPrimaryWeapon(WeaponType.ROCKET_STINGER); } if (game.Input.HasKeyJustBeenPressed("Player1.PrimaryWeapon.Select4")) { SetPrimaryWeapon(WeaponType.PLASMAGUN); } if (game.Input.HasKeyJustBeenPressed("Player1.PrimaryWeapon.SwitchUp")) { SwitchUp(true); } if (game.Input.HasKeyJustBeenPressed("Player1.PrimaryWeapon.SwitchDown")) { SwitchDown(true); } if (game.Input.HasKeyJustBeenPressed("Player1.SecondaryWeapon.Select1")) { SetSecondaryWeapon(WeaponType.ULTRA_PHASER); } if (game.Input.HasKeyJustBeenPressed("Player1.SecondaryWeapon.Select2")) { SetSecondaryWeapon(WeaponType.MINIGUN); } if (game.Input.HasKeyJustBeenPressed("Player1.SecondaryWeapon.Select3")) { SetSecondaryWeapon(WeaponType.ROCKET_STINGER); } if (game.Input.HasKeyJustBeenPressed("Player1.SecondaryWeapon.Select4")) { SetSecondaryWeapon(WeaponType.PLASMAGUN); } if (game.Input.HasKeyJustBeenPressed("Player1.SecondaryWeapon.SwitchUp")) { SwitchUp(false); } if (game.Input.HasKeyJustBeenPressed("Player1.SecondaryWeapon.SwitchDown")) { SwitchDown(false); } }
public PrimaryWeaponDTO(PrimaryWeapon item) : base(item) { AmountBalls = item.AmountBalls; ShootingRange = item.ShootingRange; }
/// <summary> /// Processes the player fields. /// </summary> public void Process() { Health.Process(); PrimaryWeapon.Process(); SecondaryWeapon.Process(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // /// </summary> protected override void UpdatePlayerControlledMovement() { _Agent.enabled = false; if (_ObjectState == WorldObjectStates.Active) { // Update base rotation _BaseRotation = Input.GetAxis("Horizontal") * BaseRotationSpeed * Time.deltaTime; if (_BaseRotation != 0) { transform.eulerAngles += new Vector3(0f, _BaseRotation, 0f); } // Forward input if (Input.GetAxis("Vertical") > 0f) { // Apply forward acceleration _CurrentSpeed += Acceleration; // Clamp to top speed if (_CurrentSpeed > MaxSpeed) { _CurrentSpeed = MaxSpeed; } } // Reverse input else if (Input.GetAxis("Vertical") < 0f) { // Apply deceleration _CurrentSpeed -= Deceleration; // Clamp to top reverse speed if (_CurrentSpeed < MaxReverseSpeed) { _CurrentSpeed = MaxReverseSpeed; } } // No input else { // Slowly decelerate to a stop if (_CurrentSpeed > 0.01) { _CurrentSpeed -= Deceleration * 0.5f; } else if (_CurrentSpeed < -0.01) { _CurrentSpeed += Deceleration * 0.5f; } else { _CurrentSpeed = 0f; } } // Update weapon rotation _WeaponRotation = Input.GetAxis("Mouse X") * WeaponRotationSpeed * Time.deltaTime; if (WeaponObject && _WeaponRotation != 0) { WeaponObject.transform.eulerAngles += new Vector3(0f, _WeaponRotation, 0f); } // Check for weapon firing input if (Input.GetMouseButtonDown(0)) { // If theres a weapon attached if (PrimaryWeapon) { // Fire the weapon if possible if (PrimaryWeapon.CanFire()) { PrimaryWeapon.FireWeapon(); } } } } }
public PenaltySet(PrimaryWeapon i, Creature c) { StrPenalty = Math.Max(0, (i.StrReq - c.Str) * (i.StrReq - c.Str)); DexPenalty = Math.Max(0, (i.DexReq - c.Dex) * (i.DexReq - c.Dex)); IntPenalty = Math.Max(0, (i.AffReq - c.Aff) * (i.AffReq - c.Aff)); }