protected virtual NPCInst SpawnCharacter(ArenaClient client, WorldInst world, PosAng spawnPoint) { // only spawn if player has joined the game mode and chosen a class if (client == null || !client.GMJoined || client.GMClass == null) { return(null); } // get rid of old character if there is one client.KillCharacter(); NPCInst npc = CreateNPC(client.GMClass, (int)client.GMTeamID, client.CharInfo); npc.Spawn(world, spawnPoint.Position, spawnPoint.Angles); client.SetControl(npc); // start the warm up phase as soon as the first player joins if (Phase == GamePhase.None && players.Count(p => p.IsCharacter) == 1) { SetPhase(GamePhase.WarmUp); phaseTimer.SetInterval(Scenario.WarmUpDuration); phaseTimer.SetCallback(Fight); phaseTimer.Restart(); } return(npc); }
static void SpawnPlayer(ArenaClient client) { var charInfo = client.CharInfo; NPCInst npc = new NPCInst(NPCDef.Get(charInfo.BodyMesh == HumBodyMeshs.HUM_BODY_NAKED0 ? "maleplayer" : "femaleplayer")) { UseCustoms = true, CustomBodyTex = charInfo.BodyTex, CustomHeadMesh = charInfo.HeadMesh, CustomHeadTex = charInfo.HeadTex, CustomVoice = charInfo.Voice, CustomFatness = charInfo.Fatness, CustomScale = new Vec3f(charInfo.BodyWidth, 1.0f, charInfo.BodyWidth), CustomName = charInfo.Name }; foreach (string e in client.HordeClass.Equipment) { ItemInst item = new ItemInst(ItemDef.Get(e)); npc.Inventory.AddItem(item); npc.EffectHandler.TryEquipItem(item); } if (client.HordeClass.NeedsBolts) { } npc.Inventory.AddItem(new ItemInst(ItemDef.Get("hptrank"))); Vec3f spawnPos = Randomizer.GetVec3fRad(activeDef.SpawnPos, activeDef.SpawnRange); Angles spawnAng = Randomizer.GetYaw(); //npc.TeamID = 0; npc.Spawn(activeWorld, spawnPos, spawnAng); client.SetControl(npc); }
static NPCInst SpawnEnemy(HordeEnemy enemy, Vec3f spawnPoint, float spawnRange = 100) { NPCInst npc = new NPCInst(NPCDef.Get(enemy.NPCDef)); if (enemy.WeaponDef != null) { ItemInst item = new ItemInst(ItemDef.Get(enemy.WeaponDef)); npc.Inventory.AddItem(item); npc.EffectHandler.TryEquipItem(item); } if (enemy.ArmorDef != null) { ItemInst item = new ItemInst(ItemDef.Get(enemy.ArmorDef)); npc.Inventory.AddItem(item); npc.EffectHandler.TryEquipItem(item); } npc.SetHealth(enemy.Health, enemy.Health); Vec3f spawnPos = Randomizer.GetVec3fRad(spawnPoint, spawnRange); Angles spawnAng = Randomizer.GetYaw(); //npc.TeamID = 1; npc.BaseInst.SetNeedsClientGuide(true); npc.Spawn(activeWorld, spawnPos, spawnAng); return(npc); }
static void NPCInst_sOnNPCInstMove(NPCInst npc, Vec3f oldPos, Angles oldAng, NPCMovement oldMovement) { if (npc.IsDead || !npc.IsPlayer || npc.IsUnconscious) { return; } ArenaClient client = (ArenaClient)npc.Client; if (client.HordeClass == null) { return; } if (ActiveStandInst != null) { return; } foreach (var s in ActiveStands) { if (npc.GetPosition().GetDistance(s.Stand.Position) < s.Stand.Range) { StartStand(s); break; } } }
public static void Activate(NPCInst npc) { if (currentPlayer != null) { currentPlayer.OnDeath -= DeactivateHandler; currentPlayer.OnRevive -= ActivateHandler; currentPlayer.OnDespawn -= DeactivateHandler; currentPlayer.OnSpawn -= ActivateHandler; currentPlayer.OnUnconChange -= UnconHandler; } currentPlayer = npc; if (npc == null) { return; } npc.OnDeath += DeactivateHandler; npc.OnRevive += ActivateHandler; npc.OnDespawn += DeactivateHandler; npc.OnSpawn += ActivateHandler; npc.OnUnconChange += UnconHandler; if (npc.IsSpawned && !npc.IsDead && !npc.IsUnconscious) { Activate(); } }
public override void Open() { if (Opened) { return; } player = ScriptClient.Client.Character; if (player == null || player.IsDead || player.IsInFightMode || player.ModelInst.IsInAnimation()) { return; } var env = player.Environment; if (env.InAir || env.WaterLevel > 0.4f) { return; } player.SetMovement(NPCMovement.Stand); player.Inventory.OnItemAmountChange += UpdateAmountEventMethod; player.Inventory.OnAddItem += UpdateInventory; player.Inventory.OnRemoveItem += UpdateInventory; player.OnEquip += Player_OnEquip; player.OnUnequip += Player_OnUnequip; base.Open(); inv.SetContents(player.Inventory); inv.Show(); inv.Enabled = true; }
public void Attack(NPCInst npc, FightMoves move) { var stream = npc.BaseInst.GetScriptCommandStream(); switch (move) { case FightMoves.Fwd: stream.Write((byte)RequestMessageIDs.AttackForward); break; case FightMoves.Left: stream.Write((byte)RequestMessageIDs.AttackLeft); break; case FightMoves.Right: stream.Write((byte)RequestMessageIDs.AttackRight); break; case FightMoves.Run: stream.Write((byte)RequestMessageIDs.AttackRun); break; case FightMoves.Parry: stream.Write((byte)RequestMessageIDs.Parry); break; case FightMoves.Dodge: stream.Write((byte)RequestMessageIDs.Dodge); break; default: return; } NPC.SendScriptCommand(stream, NetPriority.Immediate); }
public void Aim(NPCInst npc, bool doAim) { var stream = npc.BaseInst.GetScriptCommandStream(); stream.Write((byte)(doAim ? RequestMessageIDs.Aim : RequestMessageIDs.Unaim)); NPC.SendScriptCommand(stream, NetPriority.High); }
static void OnHit(NPCInst attacker, NPCInst target, int damage) { if (!IsActive || ActiveMode.Phase < GamePhase.Fight) { return; } if (target.HP <= 0 && attacker.Client is ArenaClient attClient && target.Client is ArenaClient tarClient && attClient.GMTeamID >= 0 && tarClient.GMTeamID >= 0) { if (attClient.GMTeamID != tarClient.GMTeamID) { attClient.GMScore++; attClient.GMKills++; attClient.TDMTeam.Score++; attClient.SendPointsMessage(+1); tarClient.GMDeaths++; if (attClient.TDMTeam.Score >= ScoreLimit) { ActiveMode.FadeOut(); } } else // teamkill { attClient.GMScore--; attClient.TDMTeam.Score--; attClient.SendPointsMessage(-1); tarClient.GMDeaths++; } } }
protected override NPCInst SpawnNPC(NPCClass classDef, Vec3f pos, Angles ang, float posOffset = 100, int teamID = 1, bool giveAI = true) { NPCInst npc = base.SpawnNPC(classDef, pos, ang, posOffset, teamID, giveAI); npc.AllowHitTarget.Add(OnAllowHit); return(npc); }
void OnHit(NPCInst attacker, NPCInst target, int damage) { if (!IsActive || ActiveMode.Phase < GamePhase.Fight) { return; } if (attacker.IsPlayer) { if (target.IsPlayer) { return; } ArenaClient player = (ArenaClient)attacker.Client; player.GMScore += damage / 10.0f; if (target.HP <= 0) { player.GMKills++; player.GMScore += 5; } } else if (target.IsPlayer) { ArenaClient player = (ArenaClient)target.Client; if (target.HP <= 1) { player.GMDeaths++; if (players.TrueForAll(p => !p.IsCharacter || p.Character.IsDead || p.Character.IsUnconscious)) { HordeFadeOut(false); } } } }
public void DrawFists(NPCInst npc) { var stream = npc.BaseInst.GetScriptCommandStream(); stream.Write((byte)RequestMessageIDs.DrawFists); NPC.SendScriptCommand(stream, NetPriority.Medium); }
public BaseVob CreateVob(byte type) { BaseVobInst vob; switch ((VobType)type) { case VobType.Vob: vob = new VobInst(); break; case VobType.Mob: vob = new MobInst(); break; case VobType.Item: vob = new ItemInst(); break; case VobType.NPC: vob = new NPCInst(); break; case VobType.Projectile: vob = new ProjInst(); break; default: throw new Exception("Unsupported VobType: " + (VobType)type); } return(vob.BaseInst); }
void DoUnconstuff(NPCInst hero) { if (hero?.Environment == null || hero?.BaseInst?.gAI == null) { return; } var env = hero.Environment; if (env.WaterLevel < 0.2f) { if (env.InAir) { return; } var gAi = hero.BaseInst.gAI; if (!gAi.CheckEnoughSpaceMoveForward(false)) { return; } if (!gAi.CheckEnoughSpaceMoveBackward(false)) { return; } if (!gAi.CheckEnoughSpaceMoveLeft(false)) { return; } if (!gAi.CheckEnoughSpaceMoveRight(false)) { return; } _LastValidPos = hero.GetPosition(); } else { if (!hero.IsUnconscious && env.WaterLevel > 0.3f && _SwimTimer.IsReady) { ScreenScrollText.AddText("Du kannst ja gar nicht schwimmen!?!"); } if (!hero.IsUnconscious) { _DoneUncon = false; } if (!_DoneUncon && hero.IsUnconscious) { hero.BaseInst.SetPhysics(false); var rb = WinApi.Process.ReadInt(hero.BaseInst.gVob.Address + 224); using (var vec = Vec3f.Null.CreateGVec()) WinApi.Process.THISCALL <WinApi.NullReturnCall>(rb, 0x5B66D0, vec); Vec3f.Null.SetGVec(hero.BaseInst.gAI.Velocity); hero.SetPosition(_LastValidPos); _DoneUncon = true; } } }
public void Voice(NPCInst npc, VoiceCmd cmd) { var stream = npc.BaseInst.GetScriptCommandStream(); stream.Write((byte)RequestMessageIDs.Voice); stream.Write((byte)cmd); NPC.SendScriptCommand(stream, NetPriority.Low); }
public void UseItem(NPCInst npc, ItemInst item) { var stream = npc.BaseInst.GetScriptCommandStream(); stream.Write((byte)RequestMessageIDs.UseItem); stream.Write((ushort)item.ID); NPC.SendScriptCommand(stream, NetPriority.Low); }
partial void pAfterSetControl(NPCInst npc) { // new npc if (npc.IsSpawned && npc.IsDead) { npc.World.DespawnList_NPC.RemoveVob(npc); } }
partial void pBeforeSetControl(NPCInst npc) { // old npc if (npc.IsSpawned && npc.IsDead) { npc.World.DespawnList_NPC.AddVob(npc); } }
public void HelpUp(NPCInst npc, NPCInst target) { var stream = npc.BaseInst.GetScriptCommandStream(); stream.Write((byte)RequestMessageIDs.HelpUp); stream.Write((ushort)target.ID); NPC.SendScriptCommand(stream, NetPriority.Low); }
protected override NPCInst SpawnCharacter(ArenaClient client, WorldInst world, PosAng spawnPoint) { NPCInst pc = base.SpawnCharacter(client, world, spawnPoint); pc.AllowHitTarget.Add(OnAllowHit); pc.DropUnconsciousOnDeath = true; pc.UnconsciousDuration = -1; return(pc); }
static void NPCInst_sOnHit(NPCInst attacker, NPCInst target, int damage) { if (target.HP <= 1 && attacker.Client is ArenaClient attClient && target.Client is ArenaClient tarClient && attClient.DuelEnemy == tarClient) { DuelWin(attClient); } }
public void Shoot(NPCInst npc, Vec3f start, Vec3f end) { var stream = npc.BaseInst.GetScriptCommandStream(); stream.Write((byte)RequestMessageIDs.Shoot); stream.Write(start); stream.Write(end); NPC.SendScriptCommand(stream, NetPriority.Immediate); }
protected virtual NPCInst SpawnNPC(NPCClass classDef, Vec3f pos, Angles ang, float posOffset = 100, int teamID = 1, bool giveAI = true) { NPCInst npc = CreateNPC(classDef, teamID); Vec3f spawnPos = posOffset > 0 ? Randomizer.GetVec3fRad(pos, posOffset) : pos; npc.BaseInst.SetNeedsClientGuide(giveAI); npc.Spawn(World, spawnPos, ang); return(npc); }
public void FMSpawn() { if (GameMode.IsActive) { GameMode.ActiveMode.Leave(this); } KillCharacter(); SetTeamID(TeamIdent.FFAPlayer); NPCDef def = NPCDef.Get(charInfo.BodyMesh == HumBodyMeshs.HUM_BODY_NAKED0 ? "maleplayer" : "femaleplayer"); NPCInst npc = new NPCInst(def) { UseCustoms = true, CustomBodyTex = charInfo.BodyTex, CustomHeadMesh = charInfo.HeadMesh, CustomHeadTex = charInfo.HeadTex, CustomVoice = charInfo.Voice, CustomFatness = charInfo.Fatness, CustomScale = new Vec3f(charInfo.BodyWidth, 1.0f, charInfo.BodyWidth), CustomName = charInfo.Name, DropUnconsciousOnDeath = true, UnconsciousDuration = 15 * TimeSpan.TicksPerSecond, }; ItemDef.ForEach(itemDef => { var item = new ItemInst(itemDef); npc.Inventory.AddItem(item); if (string.Equals(itemDef.CodeName, "ItMw_1h_Bau_Mace", StringComparison.OrdinalIgnoreCase) || string.Equals(itemDef.CodeName, "ITAR_Prisoner", StringComparison.OrdinalIgnoreCase)) { npc.EffectHandler.TryEquipItem(item); } else if (itemDef.ItemType == ItemTypes.AmmoBow || itemDef.ItemType == ItemTypes.AmmoXBow) { item.SetAmount(100); } }); if (npc.ModelDef.TryGetOverlay("1HST1", out ScriptOverlay ov)) { npc.ModelInst.ApplyOverlay(ov); } if (npc.ModelDef.TryGetOverlay("2HST1", out ov)) { npc.ModelInst.ApplyOverlay(ov); } var pair = spawnPositions.GetRandom(); npc.Spawn(WorldInst.List[0], pair.Item1, pair.Item2); this.SetControl(npc); npc.AllowHitAttacker.Add(DuelMode.CheckHitDetection); }
public static bool CheckHitDetection(NPCInst attacker, NPCInst target) { if (attacker.Client is ArenaClient attClient && target.Client is ArenaClient tarClient) { if (attClient.DuelEnemy != tarClient) { return(false); } } return(true); }
static void UnconHandler(NPCInst npc) { if (npc.IsUnconscious) { Activate(); } else { Deactivate(); } }
public void Climb(NPCInst npc, NPC.ClimbingLedge ledge) { if (!jumpTimer.IsReady) { return; } ClimbMoves move; var gAI = npc.BaseInst.gAI; float dist = ledge.Location.Y - gAI.FeetY; if (dist < gAI.StepHeight) { return; } else if (dist < gAI.YMaxJumpLow) { move = ClimbMoves.Low; } else if (dist < gAI.YMaxJumpMid) { move = ClimbMoves.Mid; } else { move = ClimbMoves.High; } var stream = npc.BaseInst.GetScriptCommandStream(); switch (move) { case ClimbMoves.High: stream.Write((byte)RequestMessageIDs.ClimbHigh); break; case ClimbMoves.Mid: stream.Write((byte)RequestMessageIDs.ClimbMid); break; case ClimbMoves.Low: stream.Write((byte)RequestMessageIDs.ClimbLow); break; default: return; } ledge.WriteStream(stream); NPC.SendScriptCommand(stream, NetPriority.Medium); }
public void DrawWeapon(NPCInst npc, ItemInst item) { if (npc == null || item == null) { return; } var stream = npc.BaseInst.GetScriptCommandStream(); stream.Write((byte)RequestMessageIDs.DrawWeapon); stream.Write((byte)item.ID); NPC.SendScriptCommand(stream, NetPriority.Medium); }
public static void SendRequest(NPCInst target) { if (!requestTime.IsReady) { return; } var stream = ArenaClient.GetScriptMessageStream(); stream.Write((byte)ScriptMessages.DuelRequest); stream.Write((ushort)target.ID); ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Unreliable); }
public void TryHelpUp(NPCInst target) { if (Host.IsDead || Host.Movement != NPCMovement.Stand || Host.ModelInst.IsInAnimation() || Host.Environment.InAir || Host.IsUnconscious || !target.IsUnconscious || target.GetPosition().GetDistance(Host.GetPosition()) > 300) { return; } float speed = 1.0f; this.Host.ModelInst.StartAniJob(Host.AniCatalog.Gestures.Plunder, speed); this.Host.DoVoice((VoiceCmd)(1 + this.Host.Guild)); target.LiftUnconsciousness(); OnHelpUp?.Invoke(this.Host); }