void Server_GrindingFloatingObject(IMyFloatingObject floatingObject, ref MyDamageInformation info, ulong attackerSteamId) { PrecisionData data; if (!Server_PrecisionData.TryGetValue(attackerSteamId, out data) || data.GridEntId == 0) { return; } // prevent all floating object damage while in precision mode info.Amount = 0; }
void BeforeDamage(object target, ref MyDamageInformation info) { try { if (info.IsDeformation || info.Amount <= 0 || info.Type != MyDamageType.Grind) { return; } IMySlimBlock block = target as IMySlimBlock; IMyFloatingObject fo = (block == null ? target as IMyFloatingObject : null); if (block == null && fo == null) { return; } MyEntity attacker = MyEntities.GetEntityById(info.AttackerId); IMyAngleGrinder grinder = attacker as IMyAngleGrinder; IMyCharacter attackerChar = (grinder == null ? attacker as IMyCharacter : null); if (grinder == null && attackerChar == null) { return; } ulong attackerSteamId; if (grinder != null) { attackerSteamId = MyAPIGateway.Players.TryGetSteamId(grinder.OwnerIdentityId); } else { attackerSteamId = MyAPIGateway.Players.TryGetSteamId(attackerChar.ControllerInfo.ControllingIdentityId); } if (block != null) { GrindingBlock?.Invoke(block, ref info, grinder, attackerSteamId); } else { GrindingFloatingObject?.Invoke(fo, ref info, attackerSteamId); } } catch (Exception e) { Log.Error(e); } }
private void CombatDamageHandler(object target, MyDamageInformation info) { if (info.Amount == 0) { return; } CombatDescription log = new CombatDescription { Damage = info.Amount, Type = info.Type.String, Timestamp = Tools.DateTime }; if (target is IMySlimBlock) { IMySlimBlock slim = target as IMySlimBlock; log.Integrity = slim.Integrity; log.VictimGridId = slim.CubeGrid.EntityId; log.VictimGridBlockId = Tools.GetBlockId(slim.Position); } else if (target is IMyCharacter) { IMyCharacter character = target as IMyCharacter; // characters keep getting hit after death we dont want to log that if (character.Name == AlreadyLogged) { return; } if (character.Integrity <= 0) { character.Name = AlreadyLogged; } log.VictimEntityId = character.EntityId; log.Integrity = character.Integrity; } else if (target is IMyFloatingObject) { IMyFloatingObject obj = (target as IMyFloatingObject); log.VictimEntityId = obj.EntityId; log.Integrity = obj.Integrity; } else { ActivityCollector.Log.Error($"Unrecognised Victim {target.GetType()}"); } IMyEntity entity = MyAPIGateway.Entities.GetEntityById(info.AttackerId); if (entity == null) { } else if (entity is IMyCubeBlock) { IMyCubeBlock cube = entity as IMyCubeBlock; log.AttackerGridId = cube.CubeGrid.EntityId; log.AttackerEntityId = cube.EntityId; } else if (entity is IMyCharacter) { try { IMyCharacter character = entity as IMyCharacter; if (character.Name != null) // hacks continued { long missileId = -1; long.TryParse(entity.Name, out missileId); if (missileId != -1) { IMyEntity missileEntity = MyAPIGateway.Entities.GetEntityById(missileId); if (missileEntity != null) { if (missileEntity is IMyCubeGrid) { IMyCubeGrid grid = missileEntity as IMyCubeGrid; log.AttackerGridId = grid.EntityId; } else { IMyCubeBlock cube = missileEntity as IMyCubeBlock; log.AttackerGridId = cube.CubeGrid.EntityId; log.AttackerGridBlockId = Tools.GetBlockId(cube.Position); } } else { ActivityCollector.Log.Error($"missiles parent grid was not found!"); } } else { ActivityCollector.Log.Error($"Entity of type {entity.GetType()} failed to parse id {entity.Name}"); } } else { log.AttackerEntityId = character.EntityId; } } catch (Exception e) { ActivityCollector.Log.Error(e); } } else if (entity is IMyGunBaseUser) // player tools { IMyGunBaseUser gun = entity as IMyGunBaseUser; log.AttackerEntityId = gun.Weapon.EntityId; } else if (entity is IMyEngineerToolBase) { IMyEngineerToolBase toolbase = entity as IMyEngineerToolBase; log.AttackerEntityId = toolbase.EntityId; } else if (entity is IMySlimBlock) { IMySlimBlock slim = entity as IMySlimBlock; log.AttackerGridId = slim.CubeGrid.EntityId; if (slim.FatBlock != null) { log.AttackerEntityId = slim.FatBlock.EntityId; } else { } } else if (entity is IMyCubeGrid) { IMyCubeGrid grid = entity as IMyCubeGrid; log.AttackerGridId = grid.EntityId; } else if (entity is MyVoxelBase) { MyVoxelBase voxel = entity as MyVoxelBase; log.AttackerEntityId = entity.EntityId; } else if (entity.GetType().Name == "MyMissile") { long missileId = -1; long.TryParse(entity.Name, out missileId); if (missileId != -1) { IMyEntity missileEntity = MyAPIGateway.Entities.GetEntityById(missileId); if (missileEntity != null) { if (missileEntity is IMyCubeGrid) { IMyCubeGrid grid = missileEntity as IMyCubeGrid; log.AttackerGridId = grid.EntityId; } else { IMyCubeBlock cube = missileEntity as IMyCubeBlock; log.AttackerGridId = cube.CubeGrid.EntityId; log.AttackerEntityId = cube.EntityId; } } else { ActivityCollector.Log.Error($"Missles parent grid was not found!"); } } else { ActivityCollector.Log.Error($"Entity of type {entity.GetType()} failed to parse id {entity.Name}"); } } else { ActivityCollector.Log.Error($"Unknown attacker entity of type: {entity.GetType()}"); } SQLQueryData.WriteToDatabase(log); }
public static VRage.MyFixedPoint GetAmount(this IMyFloatingObject FloatingObject) { return((FloatingObject as MyFloatingObject).Amount); }
public static void PickupItem(this IMyInventory Inventory, IMyFloatingObject FloatingObject) { (Inventory as MyInventory).TakeFloatingObject(FloatingObject as MyFloatingObject); }