예제 #1
0
        public static void SendAttackNotification(IMyFaction attacker, IMyFaction defender, long attackerId, ulong playerSteamid, Vector3 position)
        {
            if (defender != null)
            {
                if (attacker != null && !attacker.Equals(defender))
                {
                    if (blockCooldowns.TryGetValue(attackerId, out DateTime time))
                    {
                        if (DateTime.Now >= time)
                        {
                            if (MySession.Static.Players.TryGetPlayerBySteamId(playerSteamid) != null)
                            {
                                Vector3 playerPos = MySession.Static.Players.TryGetPlayerBySteamId(playerSteamid).GetPosition();
                                float   distance  = Vector3.Distance(playerPos, position);
                                if (distance > 10000)
                                {
                                    return;
                                }
                            }
                            NotificationMessage message;

                            message = new NotificationMessage("You are attacking " + defender.Tag, 5000, "Red");
                            //this is annoying, need to figure out how to check the exact world time so a duplicate message isnt possible
                            ModCommunication.SendMessageTo(message, playerSteamid);
                            blockCooldowns.Remove(attackerId);
                            blockCooldowns.Add(attackerId, DateTime.Now.AddSeconds(11));
                        }
                    }
                    else
                    {
                        if (MySession.Static.Players.TryGetPlayerBySteamId(playerSteamid) != null)
                        {
                            Vector3 playerPos = MySession.Static.Players.TryGetPlayerBySteamId(playerSteamid).GetPosition();
                            float   distance  = Vector3.Distance(playerPos, position);
                            if (distance > 10000)
                            {
                                return;
                            }
                        }

                        blockCooldowns.Remove(attackerId);
                        blockCooldowns.Add(attackerId, DateTime.Now.AddSeconds(11));
                        ModCommunication.SendMessageTo(new NotificationMessage("You are attacking " + defender.Tag, 5000, "Red"), playerSteamid);
                    }
                }
            }
            return;
        }
예제 #2
0
        private void DamageCheck(object target, ref MyDamageInformation info)
        {
            if (file != null)
            {
                if (file.LogNeutralsDamagingEachOther || file.ShowFactionTagsOnDamageGrid)
                {
                    try
                    {
                        if (!(target is MySlimBlock block))
                        {
                            return;
                        }
                        long       attackerId = GetAttacker(info.AttackerId);
                        MyIdentity id         = MySession.Static.Players.TryGetIdentity(attackerId);
                        if (id == null)
                        {
                            return;
                        }
                        IMyFaction defender = FacUtils.GetPlayersFaction(FacUtils.GetOwner(block.CubeGrid));
                        IMyFaction attacker = FacUtils.GetPlayersFaction(id.IdentityId);
                        if (file.ShowFactionTagsOnDamageGrid)
                        {
                            if (Sync.Players.TryGetPlayerId(id.IdentityId, out MyPlayer.PlayerId player))
                            {
                                if (MySession.Static.Players.GetPlayerById(player) != null)
                                {
                                    SendAttackNotification(attacker, defender, attackerId, player.SteamId, block.CubeGrid.PositionComp.GetPosition());
                                }
                            }
                        }


                        MyCubeBlock cubeBlock = block.FatBlock;
                        if (cubeBlock == null)
                        {
                            return;
                        }



                        if (cubeBlock as MyTerminalBlock == null)
                        {
                            return;
                        }

                        if (cubeBlock.EntityId == 0L)
                        {
                            return;
                        }

                        if (GetAttacker(info.AttackerId) > 0L)
                        {
                            //this is so messy
                            if (attacker != null && defender != null)
                            {
                                if (attacker.Equals(defender))
                                {
                                    return;
                                }

                                if (MySession.Static.Factions.AreFactionsFriends(attacker.FactionId, defender.FactionId) || MySession.Static.Factions.AreFactionsNeutrals(attacker.FactionId, defender.FactionId))
                                {
                                    if (blockCooldowns.TryGetValue(cubeBlock.EntityId, out DateTime time))
                                    {
                                        if (DateTime.Now < time)
                                        {
                                            return;
                                        }
                                    }
                                    if (file.ShowFactionTagsOnDamageGrid)
                                    {
                                        blockCooldowns.Remove(cubeBlock.EntityId);
                                        blockCooldowns.Add(cubeBlock.EntityId, DateTime.Now.AddSeconds(10));
                                        CrunchUtilitiesPlugin.Log.Info("FACTIONLOG Attacking while not at war " + attackerId + " " + attacker.Tag + " " + attacker.FactionId + " against " + cubeBlock.CubeGrid.DisplayName + ", " + defender.Tag + " " + defender.FactionId);
                                    }
                                }
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error(e, "Error on Checking Damage!");
                    }
                }
            }
        }