public override void _Ready() { if (mobDef == null) { Console.WriteLine($"EntMob had no mob type set - getting default"); mobDef = Main.i.factory.GetMobType(GameFactory.MobType_Humanoid); } _health = mobDef.defaultHealth; // find Godot scene nodes body = GetNode <KinematicWrapper>("actor_base"); body.SetCallbacks(OnHealthChange, OnDeath); body.InitHealth(mobDef.defaultHealth, mobDef.defaultHealth); body.actor = this; if (_entId == 0) { // no id previous set, request one Console.WriteLine($"EntMob - no id set - registering self"); _entId = Main.i.game.ReserveActorId(1); Main.i.game.RegisterActor(this); } prjDef = new ProjectileDef(); prjDef.damage = 10; prjDef.launchSpeed = 100; prjDef.prefabPath = GameFactory.Path_PointProjectile; prjDef.speedMode = ProjectileDef.SpeedMode.Accel; prjDef.maxSpeed = 100; prjDef.minSpeed = 10; prjDef.accelPerSecond = -300; _debugSb.Clear(); _debugSb.Append($"EntMob Id {_entId}"); }
protected override void FireProjectile(int index) { List <ProjectileDef> projectilesToSpawn = new List <ProjectileDef>(); for (int i = 0; i < bullets; i++) { ProjectileDef pDef = new ProjectileDef() { projectileObject = projectile, spawnLocation = transform.position + transform.parent.localScale.x * Vector3.right * 2.0f }; float angle = (spreadAngle / 2 - spreadAngle / (bullets - 1) * i) * Mathf.Deg2Rad; Vector2 shotDirection = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)); shotDirection.x *= transform.parent.localScale.x; if (index > 0) { shotDirection += new Vector2(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f)); } pDef.velocity = shotDirection; pDef.owner = weaponOwner; projectilesToSpawn.Add(pDef); } StartCoroutine(SpawnProjectiles(projectilesToSpawn)); }
public void Launch( Vector3 origin, Vector3 forward, ProjectileDef def, PhysicsBody ignoreBody, Team team, int targetActorId = Game.NullActorId) { _ignoreBody = ignoreBody; _def = def; _state = State.Live; Transform t = GlobalTransform; t.origin = new Vector3(); GlobalTransform = t; Vector3 lookPos = t.origin + forward; this.LookAt(lookPos, Vector3.Up); t.origin = origin; GlobalTransform = t; _tick = def.timeToLive; _speed = def.launchSpeed; _team = team; _targetActorId = targetActorId; _hideTicks = _hideTicksMax; Hide(); }
public InvWeapDisc( Spatial launchNode, WeaponDef weaponDef, ProjectileDef primaryDef, ProjectileDef secondaryDef, PhysicsBody ignoreBody) : base(launchNode, weaponDef, primaryDef, secondaryDef, ignoreBody) { }
public InvWeapShotgun( Spatial launchNode, WeaponDef weaponDef, ProjectileDef primaryDef, ProjectileDef secondaryDef, PhysicsBody ignoreBody) : base(launchNode, weaponDef, primaryDef, secondaryDef, ignoreBody) { _roundsLoaded = weaponDef.magazineSize; }
public void Init(ProjectileDef projectileDef, Transform target) { ProjectileDef = projectileDef; rb.velocity = transform.up * ProjectileDef.Speed; SpriteRenderer.sprite = projectileDef.DisplayImages[0]; if (target != null && (ProjectileDef.IsHoming || ProjectileDef.IsFixedTarget)) { _target = target; _targetLocation = _target.transform.position; } }
//private string _mobSpawnType = string.Empty; public InvWeapGodhand( Spatial launchNode, Spatial aimLaserNode) { _launchNode = launchNode; _aimLaserNode = aimLaserNode; _riflePrjDef = new ProjectileDef(); _riflePrjDef.damage = 10000; _riflePrjDef.launchSpeed = 1000; _mobTypes = Main.i.factory.GetMobTypeList(); //_mobSpawnType = _mobTypes[0]; _mobTypeIndex = 0; //_mobSpawnType = GameFactory.MobType_Titan; UpdateDisplayName(); }
/// <summary> /// Adds all the original vanilla projectiles. /// </summary> internal static void FillVanilla() { for (int i = -65; i < ProjectileID.Count; i++) { if (i == 0) continue; Projectile p = new Projectile(); p.SetDefaults(i); ProjectileDef def = new ProjectileDef(); def.InternalName = p.name; def.Type = p.type; CopyProjectileToDef(def, p); DefFromType.Add(i, def); VanillaDefFromName.Add(p.name, def); } }
void OnDestroy() { if ((splitOnPlayerCollision && collidedWithPlayer) || !collidedWithPlayer || (collidedWithTerrain && explodeOnTerrain)) { List <ProjectileDef> projectilesToSpawn = new List <ProjectileDef>(); for (int i = 0; i < bullets; i++) { ProjectileDef pDef = new ProjectileDef() { projectileObject = shrapnelProjectile, spawnLocation = transform.position }; float angle = (spreadAngle / 2 - spreadAngle / (bullets - 1) * i + Random.Range(-MaxRandomOffset, MaxRandomOffset)) * Mathf.Deg2Rad; Vector2 shotDirection = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)); if (intialVelocity.x < 0.0f) { shotDirection.x *= -1.0f; } pDef.velocity = shotDirection; pDef.owner = projectileOwner; projectilesToSpawn.Add(pDef); } foreach (var proj in projectilesToSpawn) { var insProj = Instantiate(proj.projectileObject, proj.spawnLocation, Quaternion.identity) as Projectile; var angVelocity = Random.Range(-angularStrengthMax, angularStrengthMax); insProj.SetDirection(proj.velocity, angVelocity); insProj.SetOwner(ref proj.owner); } } }
public override void _Ready() { _model = ZqfGodotUtils.GetNodeSafe <MeshInstance>(this, "mlrs_turret/Cube"); _body = ZqfGodotUtils.GetNodeSafe <RigidBody>(this, "mlrs_turret"); _hpArea = ZqfGodotUtils.GetNodeSafe <Health>(this, "mlrs_turret/area"); if (_hpArea != null) { _hpArea.SetCallbacks(OnHealthChange, OnDeath); _hpArea.OverrideStats(Team.Mobs, 400, 400); } _idleLocalTransform = Transform; _prjDef = new ProjectileDef(); _prjDef.damage = 10; _prjDef.prefabPath = GameFactory.Path_PointProjectile; _prjDef.speedMode = ProjectileDef.SpeedMode.Basic; _prjDef.launchSpeed = 15; //_prjDef.moveMode = ProjectileDef.MoveMode.Accel; //_prjDef.launchSpeed = 100; //_prjDef.maxSpeed = 100; //_prjDef.minSpeed = 10; //_prjDef.accelPerSecond = -300; _patternDef = new PatternDef(); _patternDef.count = 8; _patternDef.patternType = PatternType.HorizontalLine; _patternDef.scale = new Vector3(4, 4, 0); _transforms = new List <Transform>(_patternDef.count); IActor actorParent = Game.DescendTreeToActor(this); if (actorParent != null) { Console.WriteLine($"Turret found parent actor {actorParent.actorId}"); } }
/*public void Launch(Transform globalOrigin, ProjectileDef def, PhysicsBody ignoreBody) * { * _ignoreBody = ignoreBody; * _def = def; * Vector3 origin = globalOrigin.origin; * Console.WriteLine($"Prj spawned at {origin.x}, {origin.y}, {origin.z}"); * GlobalTransform = globalOrigin; * _tick = def.timeToLive; * }*/ public void Launch(Vector3 origin, Vector3 forward, ProjectileDef def, PhysicsBody ignoreBody) { _ignoreBody = ignoreBody; _def = def; Transform t = GlobalTransform; t.origin = new Vector3(); GlobalTransform = t; Vector3 lookPos = t.origin + forward; this.LookAt(lookPos, Vector3.Up); //Vector3 origin = globalOrigin.origin; t.origin = origin; //Console.WriteLine($"Prj spawned at {origin.x}, {origin.y}, {origin.z}"); GlobalTransform = t; _tick = def.timeToLive; //Console.WriteLine($"Prj TTL {_tick}"); _hideTicks = _hideTicksMax; Hide(); }
static void LoadTextures(ProjectileDef def) { // def.GetTexture and GetBossHeadTexture values should be checked when it's loaded var texture = def.GetTexture(); if (texture == null) throw new ArgumentNullException("GetTexture return value is null for ProjectileDef " + def.InternalName + " from mod " + def.Mod + "."); Main.projectileTexture[def.Type] = def.GetTexture(); Main.projectileLoaded[def.Type] = true; }
static void LoadSetProperties(ProjectileDef def) { // assuming space is allocated in the ExtendArrays call Main.projFrames[def.Type] = def.TotalFrameCount; Main.projHook[def.Type] = def.IsHook; Main.projHostile[def.Type] = def.IsHostile; Main.projPet[def.Type] = def.IsPet; ProjectileID.Sets.DontAttachHideToAlpha[def.Type] = def.DontAttachHideToAlpha; ProjectileID.Sets.Homing[def.Type] = def.IsHoming; ProjectileID.Sets.LightPet[def.Type] = def.IsLightPet; ProjectileID.Sets.MinionSacrificable[def.Type] = def.IsSacrificableMinion; ProjectileID.Sets.NeedsUUID[def.Type] = def.NeedsUUID; ProjectileID.Sets.StardustDragon[def.Type] = def.IsStartustDragon; ProjectileID.Sets.TrailCacheLength[def.Type] = def.TrailCacheLength; ProjectileID.Sets.TrailingMode[def.Type] = (int)def.TrailingMode; }
static void CopyProjectileToDef(ProjectileDef tar, Projectile source) { tar.Damage = source.damage; tar.Width = source.width; tar.Height = source.height; tar.Alpha = source.alpha; tar.Scale = source.scale; tar.InternalName = source.name; if (source.melee) tar.DamageType = DamageType.Melee; else if (source.ranged) tar.DamageType = DamageType.Ranged; else if (source.magic) tar.DamageType = DamageType.Magic; else if (source.minion) tar.DamageType = DamageType.Minion; else if (source.thrown) tar.DamageType = DamageType.Thrown; tar.AiStyle = (ProjectileAiStyle)source.aiStyle; tar.GetTexture = () => Main.npcTexture[source.type]; }
// set properties aren't copied, type/netid is preserved static void CopyDefToProjectile(Projectile tar, ProjectileDef source) { tar.damage = source.Damage; tar.width = source.Width; tar.height = source.Height; tar.alpha = source.Alpha; tar.scale = source.Scale; tar.name = source.InternalName; switch (source.DamageType) { case DamageType.Melee: tar.melee = true; break; case DamageType.Ranged: tar.ranged = true; break; case DamageType.Magic: tar.magic = true; break; case DamageType.Minion: tar.minion = true; break; case DamageType.Thrown: tar.thrown = true; break; // None -> all false } //tar.counterweight; //tar.arrow; //tar.bobber; tar.hostile = source.IsHostile; tar.aiStyle = (int)source.AiStyle; }