//检测组件是否可以被安装,若是则返回JointPoints public Transform[] IsAttachableTo(WeaponComponent weaponComponent) { Attachment? attachableObject = weaponComponent.GetAttachment(componentType); if (attachableObject != null) return attachableObject.Value.attachmentJoints; else return null; }
//若存在复数个接合点,选择其中之一(默认为0) public bool JointTo(WeaponComponent component, int index = 0) { Transform[] targetJoints = IsAttachableTo(component); if (targetJoints == null) return false; if (index < 0 || index >= targetJoints.Length) return false; return componentJoint.GetComponent<ComponentJoint>().JointTo(targetJoints[index]); }
/// <summary> /// Creates this system. /// </summary> /// <param name="game"></param> public WeaponSystem(DungeonCrawlerGame game) { _game = game; //To simplfy some things, I'm keeping a reference to components I often use. _collisionComponent = _game.CollisionComponent; _equipmentComponent = _game.EquipmentComponent; _playerInfoComponent = _game.PlayerInfoComponent; _weaponComponent = _game.WeaponComponent; _weaponSpriteComponent = _game.WeaponSpriteComponent; _positionComponent = _game.PositionComponent; }
public bool shoot(GameObject attacker, GameObject target) { healthSystem = GameObject.Find("Manager").GetComponent<HealthSystem>(); currentplayerAttr = (AttributeComponent)attacker.GetComponent(typeof(AttributeComponent)); currentPlayerCell = currentplayerAttr.getCurrentCell(); currentPlayerWeapon = (WeaponComponent)currentplayerAttr.weapon.GetComponent(typeof(WeaponComponent)); if(attacker.tag == "FigurSpieler1") currentPlayerComp = GameObject.Find("Player1").GetComponent<PlayerComponent>(); else currentPlayerComp = GameObject.Find("Player2").GetComponent<PlayerComponent>(); currentTargetAttr = (AttributeComponent)target.GetComponent(typeof(AttributeComponent)); currentTargetCell = currentTargetAttr.getCurrentCell(); distanceBetweenPlayers = Vector3.Magnitude(currentTargetCell.transform.position - currentPlayerCell.transform.position); Debug.Log("Distance between players is " + distanceBetweenPlayers); if (playerCanShoot()) { float hitChance = chanceOfHittingTarget(); Debug.Log("Hitchance: " + hitChance); if (hitChance >= Random.value) { if (healthSystem == null) Debug.Log("Healthsys"); if (currentplayerAttr == null) Debug.Log("currentplayerAttr"); if (currentPlayerComp == null) Debug.Log("currentPlayerComp"); if (currentTargetAttr == null) Debug.Log("currentTargetAttr"); healthSystem.doDamage(currentplayerAttr, currentPlayerComp, currentTargetAttr, HealthSystem.SHOOT); return true; } else { return false; } } return false; }
internal void SendSetCompBoolRequest(WeaponComponent comp, bool newBool, PacketType type) { if (IsClient) { uint[] mIds; if (PlayerMIds.TryGetValue(MultiplayerId, out mIds)) { PacketsToServer.Add(new BoolUpdatePacket { MId = ++mIds[(int)type], EntityId = comp.MyCube.EntityId, SenderId = MultiplayerId, PType = type, Data = newBool, }); } else { Log.Line($"SendSetCompBoolRequest no player MIds found"); } } else if (HandlesInput) { PacketsToClient.Add(new PacketInfo { Entity = comp.MyCube, Packet = new BoolUpdatePacket { MId = ++comp.MIds[(int)type], EntityId = comp.MyCube.EntityId, SenderId = MultiplayerId, PType = type, Data = newBool, } }); } else { Log.Line($"SendSetCompBoolRequest should never be called on Non-HandlesInput"); } }
internal void SendCompState(WeaponComponent comp) { if (IsServer) { if (!comp.Session.PrunedPacketsToClient.ContainsKey(comp.Data.Repo.Base)) { const PacketType type = PacketType.CompState; comp.Data.Repo.Base.UpdateCompBasePacketInfo(comp); PacketInfo oldInfo; CompStatePacket iPacket; if (PrunedPacketsToClient.TryGetValue(comp.Data.Repo.Base.State, out oldInfo)) { iPacket = (CompStatePacket)oldInfo.Packet; iPacket.EntityId = comp.MyCube.EntityId; iPacket.Data = comp.Data.Repo.Base.State; } else { iPacket = PacketStatePool.Get(); iPacket.EntityId = comp.MyCube.EntityId; iPacket.SenderId = MultiplayerId; iPacket.PType = type; iPacket.Data = comp.Data.Repo.Base.State; } PrunedPacketsToClient[comp.Data.Repo.Base.State] = new PacketInfo { Entity = comp.MyCube, Packet = iPacket, }; } else { SendCompBaseData(comp); } } else { Log.Line($"SendCompState should never be called on Client"); } }
public static void Load(WeaponComponent comp) { string rawData; if (comp.MyCube.Storage.TryGetValue(comp.Session.MpWeaponSyncGuid, out rawData)) { var base64 = Convert.FromBase64String(rawData); try { comp.WeaponValues = MyAPIGateway.Utilities.SerializeFromBinary <WeaponValues>(base64); var timings = comp.WeaponValues.Timings; for (int i = 0; i < comp.Platform.Weapons.Length; i++) { var w = comp.Platform.Weapons[i]; var wTiming = timings[w.WeaponId].SyncOffsetClient(comp.Session.Tick); comp.Session.SyncWeapon(w, wTiming, ref w.State.Sync, false); } return; } catch (Exception e) { Log.Line($"Weapon Values Failed To load re-initing"); } } comp.WeaponValues = new WeaponValues { Targets = new TransferTarget[comp.Platform.Weapons.Length], Timings = new WeaponTimings[comp.Platform.Weapons.Length] }; for (int i = 0; i < comp.Platform.Weapons.Length; i++) { var w = comp.Platform.Weapons[i]; comp.WeaponValues.Targets[w.WeaponId] = new TransferTarget(); w.Timings = comp.WeaponValues.Timings[w.WeaponId] = new WeaponTimings(); } }
public void Save(WeaponComponent comp) { if (comp.MyCube?.Storage == null) { return; } var sv = new WeaponValues { Targets = Targets, WeaponRandom = WeaponRandom, Timings = new WeaponTimings[comp.Platform.Weapons.Length] }; for (int i = 0; i < comp.Platform.Weapons.Length; i++) { var w = comp.Platform.Weapons[i]; sv.Timings[w.WeaponId] = w.Timings.SyncOffsetServer(comp.Session.Tick); } var binary = MyAPIGateway.Utilities.SerializeToBinary(sv); comp.MyCube.Storage[comp.Session.MpWeaponSyncGuid] = Convert.ToBase64String(binary); }
public void Sync(WeaponComponent comp, CompSettingsValues syncFrom) { Guidance = syncFrom.Guidance; Modes = syncFrom.Modes; Range = syncFrom.Range; foreach (var w in comp.Platform.Weapons) { w.UpdateWeaponRange(); } Overrides.Sync(syncFrom.Overrides); if (Overload != syncFrom.Overload || RofModifier != syncFrom.RofModifier || DpsModifier != syncFrom.DpsModifier) { Overload = syncFrom.Overload; RofModifier = syncFrom.RofModifier; WepUi.SetDps(comp, syncFrom.DpsModifier, true); } }
internal static void RequestSetLeadGroup(IMyTerminalBlock block, float newValue) { var comp = block?.Components?.Get <WeaponComponent>(); if (comp == null || comp.Platform.State != MyWeaponPlatform.PlatformState.Ready) { return; } var value = (int)Math.Round(newValue, 0); if (value != comp.Data.Repo.Base.Set.Overrides.LeadGroup) { if (comp.Session.HandlesInput) { comp.Session.LeadGroupsDirty = true; } WeaponComponent.RequestSetValue(comp, "LeadGroup", value, comp.Session.PlayerId); } }
public void EquipWeapon(WeaponScriptable weaponScripable) { GameObject spawnedWeapon = Instantiate(weaponScripable.ItemPrefab, WeaponSocketLocation.position, WeaponSocketLocation.rotation, WeaponSocketLocation); if (!spawnedWeapon) { return; } if (spawnedWeapon) { WeaponComponent = spawnedWeapon.GetComponent <WeaponComponent>(); if (WeaponComponent) { GripIKLocation = WeaponComponent.GripLocation; } } WeaponComponent.Initialize(this, weaponScripable); PlayerAnimator.SetInteger("WeaponType", (int)WeaponComponent.WeaponStats.WeaponType); PlayerEvents.Invoke_OnWeaponEquipped(WeaponComponent); }
// Start is called before the first frame update void Start() { GameObject spawnedWeapon = Instantiate(weapon, socket.position, socket.rotation); if (!spawnedWeapon) { return; } spawnedWeapon.transform.parent = socket; Equipped = spawnedWeapon.GetComponent <WeaponComponent>(); Equipped.Initialize(this, reticle); GripIK = Equipped.GripLocation; PlayerAnim.SetInteger("WeaponType", (int)Equipped.stats.type); PlayerEvents.Invoke_OnWeaponEquippred(Equipped); }
public void OnWeaponSwap2(InputValue button) { Debug.Log("Working"); Destroy(spawnWeapon); spawnWeapon = null; spawnWeapon = Instantiate(Weapon2, weaponSocketLocation); if (spawnWeapon) { EquippedWeapon = spawnWeapon.GetComponent <WeaponComponent>(); if (EquippedWeapon) { EquippedWeapon.Initialize(this, PlayerCrosshair); GripIKLocation = EquippedWeapon.GripLocation; PlayerAnimator.SetInteger(WeaponTypeHash, (int)EquippedWeapon.WeaponInformation.WeaponType); } } PlayerEvent.Invoke_OnWeaponEquipped(EquippedWeapon); }
void Start() { // spawn weapon and attach to player's weapon socket GameObject spawnedweapon = Instantiate( WeapontoSpawn, WeaponSocketLocation.position, WeaponSocketLocation.rotation, WeaponSocketLocation ); if (!spawnedweapon) { return; } // set equipped weapon to spwaned weapon EquippedWeapon = spawnedweapon.GetComponent <WeaponComponent>(); if (!EquippedWeapon) { return; } // initialize weapon EquippedWeapon.Initialize(this, PCrosshair); // set grip inverse kinematic location GripIKLocation = EquippedWeapon.GripLocation; // set weapon type for animator PAnimator.SetInteger(WeaponTypeHash, (int)EquippedWeapon.WeaponInformation.WeaponType); // if (spawnedweapon) // { // // set spawned weapon's parent to player's weapon socket // spawnedweapon.transform.parent = WeaponSocketLocation; // print("Weaponspawned"); // } }
internal void SendActiveTerminal(WeaponComponent comp) { if (IsClient) { uint[] mIds; if (PlayerMIds.TryGetValue(MultiplayerId, out mIds)) { PacketsToServer.Add(new TerminalMonitorPacket { SenderId = MultiplayerId, PType = PacketType.TerminalMonitor, EntityId = comp.MyCube.EntityId, State = TerminalMonitorPacket.Change.Update, MId = ++mIds[(int)PacketType.TerminalMonitor], }); } else { Log.Line($"SendActiveTerminal no player MIds found"); } } else if (HandlesInput) { PacketsToClient.Add(new PacketInfo { Entity = comp.MyCube, Packet = new TerminalMonitorPacket { SenderId = MultiplayerId, PType = PacketType.TerminalMonitor, EntityId = comp.MyCube.EntityId, State = TerminalMonitorPacket.Change.Update, } }); } else { Log.Line($"SendActiveTerminal should never be called on Dedicated"); } }
public override bool checkProceduralPrecondition(GameObject agent) { // find the nearest supply pile that has spare tools WeaponComponent[] weapons = (WeaponComponent[])UnityEngine.GameObject.FindObjectsOfType(typeof(WeaponComponent)); WeaponComponent closest = null; float closestDist = 0; foreach (WeaponComponent weapon in weapons) { if (GetComponent <BackpackComponent>().weapon == null) { if (closest == null) { // first one, so choose it for now closest = weapon; closestDist = (weapon.gameObject.transform.position - agent.transform.position).magnitude; } else { // is this one closer than the last? float dist = (weapon.gameObject.transform.position - agent.transform.position).magnitude; if (dist < closestDist) { // we found a closer one, use it closest = weapon; closestDist = dist; } } } } if (closest == null) { return(false); } targetWeapon = closest; target = targetWeapon.gameObject; return(closest != null); }
private bool TryArm() { if (character.LockHands) { return(false); } if (Weapon != null) { if (!character.Inventory.Items.Contains(Weapon) || WeaponComponent == null) { Weapon = null; } else if (!WeaponComponent.HasRequiredContainedItems(character, addMessage: false)) { // Seek ammunition only if cannot find a new weapon if (!Reload(!HoldPosition, () => GetWeapon(out _) == null)) { if (seekAmmunition != null && subObjectives.Contains(seekAmmunition)) { return(false); } else { Weapon = null; } } } } if (Weapon == null) { Weapon = GetWeapon(out _weaponComponent); } if (Weapon == null) { Weapon = GetWeapon(out _weaponComponent, ignoreRequiredItems: true); } Mode = Weapon == null ? CombatMode.Retreat : initialMode; return(Weapon != null); }
internal static void WCShootClickAction(WeaponComponent comp, bool isTurret, bool alreadySynced = false) { var cState = comp.State.Value; if (cState.ClickShoot) { cState.CurrentPlayerControl.PlayerId = -1; cState.CurrentPlayerControl.ControlType = ControlType.None; } else { cState.CurrentPlayerControl.PlayerId = comp.Session.PlayerId; cState.CurrentPlayerControl.ControlType = isTurret ? ControlType.Ui : ControlType.Toolbar; } for (int i = 0; i < comp.Platform.Weapons.Length; i++) { var w = comp.Platform.Weapons[i]; if (cState.ClickShoot) { w.State.ManualShoot = ShootOff; } else { w.State.ManualShoot = ShootClick; } } if (comp.Session.MpActive && !alreadySynced) { comp.Session.SendControlingPlayer(comp); comp.Session.SendActionShootUpdate(comp, (cState.ClickShoot ? ShootOff : ShootClick)); } cState.ClickShoot = !cState.ClickShoot; cState.ShootOn = !cState.ClickShoot && cState.ShootOn; }
public static Entity GetWeapon(Color color) { float radius = 8f; var weaponEntity = new Entity("weapon"); var transform = new TransformComponent(weaponEntity) { LocalPosition = Vector2.Zero, LocalRotation = new Rotation(0), LocalDepth = 0.09f, Scale = new Vector2(1, 1) }; var graphics = new GraphicsComponent(weaponEntity) { TexturePath = TextureAtlas.BoxingGloveRetractedPath, Dimensions = new Point((int)(radius * 2), (int)(radius * 2)), Color = color }; var collider = new CircleColliderComponent(weaponEntity) { Radius = radius, }; var weaponComp = new WeaponComponent(weaponEntity) { ActivateThreshold = 0.75f, AttackCost = 0.1f, AttackTimeSeconds = 0.1f, CooldownTimeSeconds = 1.2f, Damage = 34f }; weaponEntity.AddComponents(transform, graphics, weaponComp, collider); return(weaponEntity); }
public void Sync(WeaponComponent comp, CompSettingsValues sync) { Guidance = sync.Guidance; Range = sync.Range; SetRange(comp); Overrides.Sync(sync.Overrides); var rofChange = Math.Abs(RofModifier - sync.RofModifier) > 0.0001f; var dpsChange = Math.Abs(DpsModifier - sync.DpsModifier) > 0.0001f; if (Overload != sync.Overload || rofChange || dpsChange) { Overload = sync.Overload; RofModifier = sync.RofModifier; DpsModifier = sync.DpsModifier; if (rofChange) { SetRof(comp); } } }
internal static void RequestSetRof(IMyTerminalBlock block, float newValue) { var comp = block?.Components?.Get <WeaponComponent>(); if (comp == null || comp.Platform.State != MyWeaponPlatform.PlatformState.Ready) { return; } if (!MyUtils.IsEqual(newValue, comp.Data.Repo.Base.Set.RofModifier)) { if (comp.Session.IsServer) { comp.Data.Repo.Base.Set.RofModifier = newValue; WeaponComponent.SetRof(comp); } else { comp.Session.SendSetCompFloatRequest(comp, newValue, PacketType.RequestSetRof); } } }
// Start is called before the first frame update void Start() { GameObject spawnedWeapon = Instantiate(WeaponToSpawn, WeaponSocketLocation.position, WeaponSocketLocation.rotation, WeaponSocketLocation); if (!spawnedWeapon) { return; } EquippedWeapon = spawnedWeapon.GetComponent <WeaponComponent>(); if (!EquippedWeapon) { return; } EquippedWeapon.Initialize(this, PlayerCrosshair); PlayerEvents.Invoke_OnWeaponEquipped(EquippedWeapon); GripIKLocation = EquippedWeapon.GripLocation; PlayerAnimator.SetInteger(WeaponTypeHash, (int)EquippedWeapon.WeaponInformation.WeaponType); }
private void UpdatePlayerClosestWeaponInfo(WeaponComponent weaponComponent) { if (weaponComponent == null) { return; } var weaponPosition = weaponComponent.transform.position; var overlappingColliderCount = Physics.OverlapSphereNonAlloc( weaponPosition, OsFps.MaxWeaponPickUpDistance, colliderBuffer ); for (var i = 0; i < overlappingColliderCount; i++) { var overlappingCollider = colliderBuffer[i]; var playerObjectComponent = overlappingCollider.gameObject .FindComponentInObjectOrAncestor <PlayerObjectComponent>(); if (playerObjectComponent != null) { var playerId = playerObjectComponent.State.Id; var distanceFromPlayerToWeapon = Vector3.Distance( overlappingCollider.ClosestPoint(weaponPosition), weaponPosition ); var distanceFromPlayerToClosestWeapon = ClosestWeaponInfoByPlayerId .GetValueOrDefault(playerId) ?.Item2 ?? float.MaxValue; if (distanceFromPlayerToWeapon < distanceFromPlayerToClosestWeapon) { var weaponId = weaponComponent.State.Id; ClosestWeaponInfoByPlayerId[playerId] = new System.Tuple <uint, float>( weaponId, distanceFromPlayerToClosestWeapon ); } } } }
internal PlatformState PlatformCrash(WeaponComponent comp, bool markInvalid, bool suppress, string message) { if (suppress) { comp.Session.SuppressWc = true; } if (markInvalid) { State = PlatformState.Invalid; } if (Comp.Session.HandlesInput) { if (suppress) { MyAPIGateway.Utilities.ShowNotification($"WeaponCore hard crashed during block init, shutting down\n Send log files to server admin or submit a bug report to mod author:\n {comp.Platform?.Structure?.ModPath} - {comp.MyCube.BlockDefinition.Id.SubtypeName}", 10000); } } Log.Line($"PlatformCrash: {Comp.MyCube.BlockDefinition.Id.SubtypeName} - {message}"); return(State); }
// Melee hyökkäys. public void Attack(InputEventArgs args) { if (args.InputState != InputState.Pressed) { return; } WeaponComponent weaponComponent = Owner.FirstComponentOfType <WeaponComponent>(); if (!weaponComponent.CanSwing) { return; } if (spriterComponent.CurrentAnimation.Name == "Attack") { return; } spriterComponent.OnAnimationFinished += spriterComponent_OnAnimationFinished; spriterComponent.ChangeAnimation("Attack"); spriterComponent.SetTime(400); }
private void Attack(TargetAttackComponent target, WeaponComponent weapon) { Transform weaponSprite = weapon.transform.Find("Sword_Sprite"); target.IsAttacking = true; if (weapon.transform.parent.name.Contains("Huge") && Random.value > 0.4f) { _hugeGuyScream.PlayMutated(); Camera.main.transform.DOShakePosition(0.5f, 0.4f, 40, 0, false, true); } DOTween.Sequence() .Append(weaponSprite.DOLocalMove(weapon.InitialPosition, 0.1f)) .AppendCallback(() => weaponSprite.GetComponent <Collider2D>().enabled = true) .AppendCallback(() => weapon.LastTimeAttackedAt = Time.time) .Append(weaponSprite.DOLocalMove(Vector3.up * weapon.Range, Mathf.Min(weapon.Speed, 0.15f))) .AppendCallback(() => weaponSprite.GetComponent <Collider2D>().enabled = false) .Append(weaponSprite.DOLocalMove(Vector3.up * weapon.Range, weapon.HitDelay)) .AppendCallback(() => target.IsAttacking = false) .Append(weaponSprite.DOLocalMove(weapon.InitialPosition, weapon.Speed * 2)) .Play(); }
internal static void RequestSetRange(IMyTerminalBlock block, float newValue) { var comp = block?.Components?.Get <WeaponComponent>(); if (comp == null || comp.Platform.State != MyWeaponPlatform.PlatformState.Ready) { return; } if (comp.Session.IsServer) { comp.Data.Repo.Base.Set.Range = newValue; WeaponComponent.SetRange(comp); if (comp.Session.MpActive) { comp.Session.SendCompBaseData(comp); } } else { comp.Session.SendSetCompFloatRequest(comp, newValue, PacketType.RequestSetRange); } }
private void SpawnShip(ShipData s, float weaponOffset) { GameObject newPattern = Instantiate(s.pattern); PatternData newPatternData = newPattern.GetComponent <PatternData>(); Transform spawnPoint = newPatternData.waypoints[0]; newPatternData.waypoints.RemoveAt(0); GameObject ship = Instantiate(s.spawnType, spawnPoint.position, spawnPoint.rotation, Gamemaster.ships.transform); EnemyShip es = ship.GetComponent <EnemyShip>(); WeaponComponent wc = ship.GetComponentInChildren <WeaponComponent>(); wc.SetInitialFireTime(weaponOffset); Logger.Instance.LogSpawn(es.stats, newPatternData); Gamemaster.Instance.totalPossiblePoints += es.stats.score; // Even if ship doesn't break, total score goes up EnemyPatternComponent epc = ship.AddComponent <EnemyPatternComponent>(); epc.patternData = newPattern; Destroy(newPattern); }
public Player(World world) { Size = new Size(100, 100); Velocity = new Vector2(Speed, 0); // Inputin alustus. defaultSetup = new InputControlSetup(); controller = new InputController(Game.Instance.InputManager); controller.ChangeSetup(defaultSetup); Game.Instance.MapManager.OnMapChanged += new MapManagerEventHandler(MapManager_OnMapChanged); animator = Game.Instance.Content.Load <CharacterModel>("playeri\\plaery").CreateAnimator("player"); animator.ChangeAnimation("attack"); animator.Scale = 0.35f; // Colliderin alustus. body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(100), ConvertUnits.ToSimUnits(100), 1.0f); body.Friction = 0f; body.BodyType = BodyType.Dynamic; body.Restitution = 0f; body.LinearDamping = 5f; body.UserData = this; Position = Vector2.Zero; Size = new Size(100, 100); HealthComponent health = new HealthComponent(100); // Komponentti alustus. components.Add(targetingComponent = new TargetingComponent <Monster>(this)); components.Add(directionalArrow = new DirectionalArrow()); components.Add(weaponComponent = new WeaponComponent(targetingComponent, new BaseballBat())); components.Add(health); Game.Instance.MapManager.OnMapChanged += new MapManagerEventHandler(MapManager_OnMapChanged); // weaponSound = Game.Instance.Content.Load<SoundEffect>("music\\baseballbat"); Speed = 15f; }
//All that this editor script does is automatically add new types of weapon component types //to the weapon type scriptable object: public override void OnInspectorGUI() { base.OnInspectorGUI(); WeaponComponentActivator inspectedObject = (WeaponComponentActivator)target; //Gotta clear out the array in the scriptable object first (just to be safe): inspectedObject.weaponType.compatibleWeaponComponentTypes = null; //Then make an empty, temporary list for weapon component types: List <WeaponComponentType> temp = new List <WeaponComponentType>(); foreach (Transform t in inspectedObject.transform) { //Pulls the weapon component from each child in the inspected weapon, //and add them to a temporary list of weapon component types: WeaponComponent weaponComponent = t.GetComponent <WeaponComponent>(); if (weaponComponent != null) { //Use a local for the weaponComponentType to make the code look clean: WeaponComponentType weaponComponentType = weaponComponent.weaponComponentType; //Makes sure that the component being added is a unique weaponComponent: if (temp.Contains(weaponComponentType) == false) { temp.Add(weaponComponentType); } } else { continue; } } //Use that temporary list of weapon component types to fill the array in the weapon type scriptable object inspectedObject.weaponType.compatibleWeaponComponentTypes = temp.ToArray(); }
// Start is called before the first frame update private void Start() { GameObject spawnedWeapon = Instantiate(Weapon, WeaponSocket.position, WeaponSocket.rotation); if (!spawnedWeapon) { return; } if (spawnedWeapon) { WeaponComponent weapon = spawnedWeapon.GetComponent <WeaponComponent>(); if (weapon) { PlayerAnimator.SetInteger("WeaponType", (int)weapon.WeaponStats.WaeaponType); spawnedWeapon.transform.parent = WeaponSocket; EquippedWeapon = spawnedWeapon.GetComponent <WeaponComponent>(); GripLocation = EquippedWeapon.HandPosition; EquippedWeapon.Initialize(this, PlayerController.CrosshairComponent); PlayerEvents.Invoke_OnWeaponEquipped(EquippedWeapon); } } }
private bool CompRestricted(WeaponComponent comp) { var grid = comp.MyCube?.CubeGrid; GridAi ai; if (grid == null || !GridTargetingAIs.TryGetValue(grid, out ai)) { return(false); } MyOrientedBoundingBoxD b; BoundingSphereD s; MyOrientedBoundingBoxD blockBox; SUtils.GetBlockOrientedBoundingBox(comp.MyCube, out blockBox); if (IsWeaponAreaRestricted(comp.MyCube.BlockDefinition.Id.SubtypeId, blockBox, grid, comp.MyCube.EntityId, ai, out b, out s)) { if (!DedicatedServer) { if (comp.MyCube.OwnerId == PlayerId) { MyAPIGateway.Utilities.ShowNotification($"Block {comp.MyCube.DisplayNameText} was placed too close to another gun", 10000); } } if (IsServer) { comp.MyCube.CubeGrid.RemoveBlock(comp.MyCube.SlimBlock); } return(true); } return(false); }
protected override bool _OnRegister(TorqueObject owner) { if (!base._OnRegister(owner)) return false; attackTimer = new Timer("hulkAttackTimer"); attackTimer.MillisecondsUntilExpire = meleeCoolDown; if(meleeRotationController != null) meleeComponent = meleeRotationController.Components.FindComponent<SwipeAttackComponent>(); if (shoulderCannonObject != null) shoulderCannon = shoulderCannonObject.Components.FindComponent<WeaponComponent>(); //SceneObject.Collision.CollidesWith -= ExtPlatformerData.MeleeDamageObjectType; return true; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { AggregateFactory = new AggregateFactory(this); WeaponFactory = new WeaponFactory(this); DoorFactory = new DoorFactory(this); RoomFactory = new RoomFactory(this); CollectableFactory = new CollectibleFactory(this); WallFactory = new WallFactory(this); EnemyFactory = new EnemyFactory(this); SkillEntityFactory = new SkillEntityFactory(this); NPCFactory = new NPCFactory(this); // Initialize Components PlayerComponent = new PlayerComponent(); LocalComponent = new LocalComponent(); RemoteComponent = new RemoteComponent(); PositionComponent = new PositionComponent(); MovementComponent = new MovementComponent(); MovementSpriteComponent = new MovementSpriteComponent(); SpriteComponent = new SpriteComponent(); DoorComponent = new DoorComponent(); RoomComponent = new RoomComponent(); HUDSpriteComponent = new HUDSpriteComponent(); HUDComponent = new HUDComponent(); InventoryComponent = new InventoryComponent(); InventorySpriteComponent = new InventorySpriteComponent(); ContinueNewGameScreen = new ContinueNewGameScreen(graphics, this); EquipmentComponent = new EquipmentComponent(); WeaponComponent = new WeaponComponent(); BulletComponent = new BulletComponent(); PlayerInfoComponent = new PlayerInfoComponent(); WeaponSpriteComponent = new WeaponSpriteComponent(); StatsComponent = new StatsComponent(); EnemyAIComponent = new EnemyAIComponent(); NpcAIComponent = new NpcAIComponent(); CollectibleComponent = new CollectibleComponent(); CollisionComponent = new CollisionComponent(); TriggerComponent = new TriggerComponent(); EnemyComponent = new EnemyComponent(); NPCComponent = new NPCComponent(); //QuestComponent = new QuestComponent(); LevelManager = new LevelManager(this); SpriteAnimationComponent = new SpriteAnimationComponent(); SkillProjectileComponent = new SkillProjectileComponent(); SkillAoEComponent = new SkillAoEComponent(); SkillDeployableComponent = new SkillDeployableComponent(); SoundComponent = new SoundComponent(); ActorTextComponent = new ActorTextComponent(); TurretComponent = new TurretComponent(); TrapComponent = new TrapComponent(); ExplodingDroidComponent = new ExplodingDroidComponent(); HealingStationComponent = new HealingStationComponent(); PortableShieldComponent = new PortableShieldComponent(); PortableStoreComponent = new PortableStoreComponent(); ActiveSkillComponent = new ActiveSkillComponent(); PlayerSkillInfoComponent = new PlayerSkillInfoComponent(); Quests = new List<Quest>(); #region Initialize Effect Components AgroDropComponent = new AgroDropComponent(); AgroGainComponent = new AgroGainComponent(); BuffComponent = new BuffComponent(); ChanceToSucceedComponent = new ChanceToSucceedComponent(); ChangeVisibilityComponent = new ChangeVisibilityComponent(); CoolDownComponent = new CoolDownComponent(); DamageOverTimeComponent = new DamageOverTimeComponent(); DirectDamageComponent = new DirectDamageComponent(); DirectHealComponent = new DirectHealComponent(); FearComponent = new FearComponent(); HealOverTimeComponent = new HealOverTimeComponent(); InstantEffectComponent = new InstantEffectComponent(); KnockBackComponent = new KnockBackComponent(); TargetedKnockBackComponent = new TargetedKnockBackComponent(); ReduceAgroRangeComponent = new ReduceAgroRangeComponent(); ResurrectComponent = new ResurrectComponent(); StunComponent = new StunComponent(); TimedEffectComponent = new TimedEffectComponent(); EnslaveComponent = new EnslaveComponent(); CloakComponent = new CloakComponent(); #endregion base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { AggregateFactory = new AggregateFactory(this); WeaponFactory = new WeaponFactory(this); DoorFactory = new DoorFactory(this); RoomFactory = new RoomFactory(this); CollectableFactory = new CollectibleFactory(this); WallFactory = new WallFactory(this); EnemyFactory = new EnemyFactory(this); // Initialize Components PlayerComponent = new PlayerComponent(); LocalComponent = new LocalComponent(); RemoteComponent = new RemoteComponent(); PositionComponent = new PositionComponent(); MovementComponent = new MovementComponent(); MovementSpriteComponent = new MovementSpriteComponent(); SpriteComponent = new SpriteComponent(); DoorComponent = new DoorComponent(); RoomComponent = new RoomComponent(); HUDSpriteComponent = new HUDSpriteComponent(); HUDComponent = new HUDComponent(); InventoryComponent = new InventoryComponent(); InventorySpriteComponent = new InventorySpriteComponent(); ContinueNewGameScreen = new ContinueNewGameScreen(graphics, this); EquipmentComponent = new EquipmentComponent(); WeaponComponent = new WeaponComponent(); BulletComponent = new BulletComponent(); PlayerInfoComponent = new PlayerInfoComponent(); WeaponSpriteComponent = new WeaponSpriteComponent(); StatsComponent = new StatsComponent(); EnemyAIComponent = new EnemyAIComponent(); CollectibleComponent = new CollectibleComponent(); CollisionComponent = new CollisionComponent(); TriggerComponent = new TriggerComponent(); EnemyComponent = new EnemyComponent(); QuestComponent = new QuestComponent(); LevelManager = new LevelManager(this); SpriteAnimationComponent = new SpriteAnimationComponent(); SkillProjectileComponent = new SkillProjectileComponent(); SkillAoEComponent = new SkillAoEComponent(); SkillDeployableComponent = new SkillDeployableComponent(); //TurretComponent = new TurretComponent(); //TrapComponent = new TrapComponent(); //PortableShopComponent = new PortableShopComponent(); //PortableShieldComponent = new PortableShieldComponent(); //MotivateComponent = new MotivateComponent(); //FallbackComponent = new FallbackComponent(); //ChargeComponent = new ChargeComponent(); //HealingStationComponent = new HealingStationComponent(); //ExplodingDroidComponent = new ExplodingDroidComponent(); base.Initialize(); }
private void DetachFromWeapon(WeaponComponent c) { Weapon w = weapon.GetComponent<Weapon>(); if (w != null) { c.GetComponent<FocusableWeaponComponent>().RenderSubComponentsWithMaterial(1); w.Detach(c, container); } }
public bool Detach(WeaponComponent component, Transform toTrans = null) { bool isDetached = RemoveWeaponComponent(component, toTrans); return isDetached; }
private void LoadWeaponComponent(GameEntity entity, WeaponComponentInfo info) { var comp = new WeaponComponent(); entity.AddComponent(comp); comp.LoadInfo(info); }
/// <summary> /// Initializes all internal members. /// </summary> public void Initialize() { T2DSceneObject weaponObj = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>(name); if (weaponObj != null) weapon = weaponObj.Components.FindComponent<WeaponComponent>(); }
public void AddComponent(WeaponComponent component) { components.Add(component); }
public bool DetachAndDestroy(WeaponComponent component) { bool isDetached = RemoveAndDestroyWeaponComponent(component); return isDetached; }
protected bool AddWeaponComponent(WeaponComponent component) { if (HasComponent(component)) return false; component.AssembleTo(transform); List<string> missingTypes = new List<string>(); CheckIntegrity(ref missingTypes); return HasComponent(component); }
public static void playShootingSound(WeaponComponent weapon) { if(weapon.shootingSound != null) { weapon.shootingSound.Play(); } else { Debug.Log("Diese Waffe hat noch keinen Sound, bitte verständigen Ihren nächstbesten Sounddesigner"); } }
public bool HasComponent(WeaponComponent component) { if (component == null) return false; WeaponComponent[] components = transform.GetComponentsInChildren<WeaponComponent>(true); foreach (WeaponComponent c in components) if (c.Equals(component)) return true; return false; }
//在Body不为Null时有效 public bool Attach(WeaponPart part, WeaponComponent component) { if (!HasComponent(component)) return false; bool isAttached = part.JointTo(component); if (isAttached) { AddWeaponComponent(part); } return isAttached; }
protected bool RemoveWeaponComponent(WeaponComponent component, Transform toTrans) { if (!HasComponent(component)) return false; if (component.Equals(body)) body = null; component.DisassembleTo(toTrans); List<string> missingTypes = new List<string>(); CheckIntegrity(ref missingTypes); return !HasComponent(component); }
public static void Invoke_OnWeaponEquipped(WeaponComponent weaponComponent) { OnWeaponEquipped?.Invoke(weaponComponent); }
public void RemoveComponent(WeaponComponent component) { components.Remove(component); }
protected override bool _OnRegister(TorqueObject owner) { if (!base._OnRegister(owner)) return false; coolDownTimer = new Timer(); idleTimer = new Timer(); coolDownTimer.MillisecondsUntilExpire = actionCoolDown; idleTimer.MillisecondsUntilExpire = 2000; launchFrame = 0; launched = false; onLeft = false; reachedBoundary = true; if (kushWeapon != null) kushWeaponComponent = kushWeapon.Components.FindComponent<WeaponComponent>(); else ; //Log Error and shit if (vineWeapon != null) vineWeaponComponent = vineWeapon.Components.FindComponent<WeaponComponent>(); else ; //Again, log some errorz ((LuaAIController)Controller).Init(this); return true; }
public static void Load(WeaponComponent comp) { string rawData; if (comp.MyCube.Storage.TryGetValue(comp.Session.MpWeaponSyncGuid, out rawData)) { var base64 = Convert.FromBase64String(rawData); try { comp.WeaponValues = MyAPIGateway.Utilities.SerializeFromBinary <WeaponValues>(base64); var timings = comp.WeaponValues.Timings; for (int i = 0; i < comp.Platform.Weapons.Length; i++) { var w = comp.Platform.Weapons[i]; var wTiming = timings[w.WeaponId].SyncOffsetClient(comp.Session.Tick); var rand = comp.WeaponValues.WeaponRandom[w.WeaponId]; rand.ClientProjectileRandom = new Random(rand.CurrentSeed); rand.TurretRandom = new Random(rand.CurrentSeed); for (int j = 0; j < rand.TurretCurrentCounter; j++) { rand.TurretRandom.Next(); } for (int j = 0; j < rand.ClientProjectileCurrentCounter; j++) { rand.ClientProjectileRandom.Next(); } comp.Session.FutureEvents.Schedule(o => { comp.Session.SyncWeapon(w, wTiming, ref w.State.Sync, false); }, null, 1); } return; } catch (Exception e) { Log.Line($"Weapon Values Failed To load re-initing"); } } comp.WeaponValues = new WeaponValues { Targets = new TransferTarget[comp.Platform.Weapons.Length], Timings = new WeaponTimings[comp.Platform.Weapons.Length], WeaponRandom = new WeaponRandomGenerator[comp.Platform.Weapons.Length], }; for (int i = 0; i < comp.Platform.Weapons.Length; i++) { var w = comp.Platform.Weapons[i]; comp.WeaponValues.Targets[w.WeaponId] = new TransferTarget(); w.Timings = comp.WeaponValues.Timings[w.WeaponId] = new WeaponTimings(); comp.WeaponValues.WeaponRandom[w.WeaponId] = new WeaponRandomGenerator(); var rand = comp.WeaponValues.WeaponRandom[w.WeaponId]; rand.CurrentSeed = Guid.NewGuid().GetHashCode(); rand.ClientProjectileRandom = new Random(rand.CurrentSeed); rand.TurretRandom = new Random(rand.CurrentSeed); rand.AcquireRandom = new Random(rand.CurrentSeed); comp.Session.FutureEvents.Schedule(o => { comp.Session.SyncWeapon(w, w.Timings, ref w.State.Sync, false); }, null, 1); } }
public void ChangeWeapon(WeaponName newWeapon, int amountOfAmmo) { //find weaopn foreach (WeaponComponent weapon in weapons) { if (weapon.name == newWeapon) { if (weapon.grade == WeaponGrade.Primary) { if (primaryWeapon) primaryWeapon.gameObject.SetActive(false); primaryWeapon = weapon; primaryWeapon.gameObject.SetActive(true); } if (weapon.grade == WeaponGrade.Secondary) { if (secondaryWeapon) secondaryWeapon.gameObject.SetActive(false); secondaryWeapon = weapon; secondaryWeapon.gameObject.SetActive(true); weaponsBar.SetShots (amountOfAmmo); } return; } } }
protected override bool _OnRegister(TorqueObject owner) { if (!base._OnRegister(owner)) return false; attackTimer = new Timer("spitterAttackTimer"); attackTimer.MillisecondsUntilExpire = coolDown; if (weakSpotTemplate != null) { weakSpotObject = weakSpotTemplate.Clone() as T2DSceneObject; foreach (T2DCollisionImage image in weakSpotObject.Collision.Images) SceneObject.Collision.InstallImage(image); } T2DSceneObject weapon = weaponTemplate.Clone() as T2DSceneObject; TorqueObjectDatabase.Instance.Register(weapon); if (weapon != null) { weapon.Mount(SceneObject, weaponLinkPoint, true); weaponComponent = weapon.Components.FindComponent<WeaponComponent>(); } justShot = false; return true; }
public void ChangeWeapon(WeaponName newWeapon) { //find weapon foreach (WeaponComponent weapon in weapons) { //find the weapon name if (weapon.name == newWeapon) { //check for primary or secondary if (weapon.grade == WeaponGrade.Primary) { if (primaryWeapon) primaryWeapon.gameObject.SetActive(false); primaryWeapon = weapon; primaryWeapon.gameObject.SetActive(true); } if (weapon.grade == WeaponGrade.Secondary) { if (secondaryWeapon) secondaryWeapon.gameObject.SetActive(false); secondaryWeapon = weapon; secondaryWeapon.gameObject.SetActive(true); } return; } } }