コード例 #1
0
ファイル: FastRepair.cs プロジェクト: WheteThunger/FastRepair
        private object OnStructureRepair(BaseCombatEntity entity, BasePlayer player)
        {
            if (!entity.repair.enabled)
            {
                return(false);
            }

            if (entity.SecondsSinceAttacked <= 30)
            {
                return(null);
            }

            var healthMissing         = entity.MaxHealth() - entity.Health();
            var healthMissingFraction = 1 - entity.healthFraction;

            if (healthMissingFraction <= 0)
            {
                return(null);
            }

            if (entity.BuildCost() == null)
            {
                return(null);
            }

            var repairAmount = Math.Max(entity.MaxHealth() * RepairFraction, MinRepairAmount);

            repairAmount = Math.Min(repairAmount, healthMissing);

            entity.health += repairAmount;
            entity.SendNetworkUpdate();

            if (entity.Health() >= entity.MaxHealth())
            {
                entity.OnRepairFinished();
            }
            else
            {
                entity.OnRepair();
            }

            return(false);
        }
コード例 #2
0
 private void OnStructureRepair(BaseCombatEntity block, BasePlayer player)
 {
     if (player == null || !configData.ChallengeSettings[Challenges.StructuresRepaired].Enabled)
     {
         return;
     }
     if (block.health < block.MaxHealth())
     {
         AddPoints(player, Challenges.StructuresRepaired, 1);
     }
 }
コード例 #3
0
        private object OnStructureRepair(BaseCombatEntity entity, BasePlayer player)
        {
            if (CanMagicHammer(player) && MagicHammerEnabled(player))
            {
                int mode = GetPlayerHammerMode(player);
                if ((mode == MODE_REPAIR && (Modes_Enabled == 1 || Modes_Enabled == 3)) || (mode == MODE_DESTROY && (Modes_Enabled == 2 || Modes_Enabled == 3)))
                {
                    if (entity.health < entity.MaxHealth() || GetPlayerHammerMode(player) == MODE_DESTROY)
                    {
                        OnStructureRepairEx(entity, player);
                        if (RETURNED == 1)
                        {
                            return(null);                            //can't afford or recently damaged
                        }
                        else
                        {
                            return(false);                            //repaired - block default repair
                        }
                    }
                    else
                    {
                        return(null);                        //full health - ignore
                    }
                }
                //Using disabled mode... send msg and change their mode to avoid spam
                else
                {
                    string str = "";
                    if (mode == MODE_REPAIR)
                    {
                        str = "repair";
                    }
                    else if (mode == MODE_DESTROY)
                    {
                        str = "destroy";
                    }
                    string parsed_config = Config["tMessageModeDisabled"].ToString();
                    parsed_config = parsed_config.Replace("{disabled_mode}", str);
                    PrintToChatEx(player, parsed_config);

                    parsed_config = Config["tHammerEnabled"].ToString();
                    parsed_config = parsed_config.Replace("{hammer_status}", "<color=#FF4000>disabled</color>");
                    PrintToChatEx(player, parsed_config);
                    SetPlayerHammerStatus(player, false);
                    return(null);                    //don't block normal repair even if plugin has repair/destroy disabled
                }
            }
            else
            {
                return(null);                //user not allowed to use MagicHammer -OR- they have it disabled (so regular repairing isn't blocked)
            }
        }
コード例 #4
0
        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
            if (info == null || info.Initiator == null || info.WeaponPrefab == null || info.InitiatorPlayer == null)
            {
                return;
            }

            BasePlayer player = info.InitiatorPlayer;

            ulong hitEntityOwnerID = entity.OwnerID != 0 ? entity.OwnerID : info.HitEntity.OwnerID;

            if (hitEntityOwnerID == 0)
            {
                return;
            }

            string MessageText = lang.GetMessage("BaseAttackedMessageTemplate", this, player.UserIDString)
                                 .Replace("{Attacker}", player.displayName)
                                 .Replace("{Owner}", GetDisplayNameByID(hitEntityOwnerID))
                                 .Replace("{Weapon}", info.WeaponPrefab.ShortPrefabName.Replace(".entity", ""))
                                 .Replace("{Structure}", entity.ShortPrefabName.Replace(".entity", ""))
                                 .Replace("{Damage}", Math.Round(info.damageTypes.Total(), 2).ToString());

            //get structure's percentage health remaining for check against threshold
            int PercentHealthRemaining = (int)((entity.Health() / entity.MaxHealth()) * 100);

            if (IsPlayerActive(hitEntityOwnerID) && IsPlayerNotificationCooledDown(hitEntityOwnerID, NotificationType.ServerNotification, Settings.ServerConfig.NotificationCooldownInSeconds))
            {
                if (PercentHealthRemaining <= Settings.ServerConfig.ThresholdPercentageHealthRemaining)
                {
                    BasePlayer p = BasePlayer.activePlayerList.Find(x => x.userID == hitEntityOwnerID);
                    PrintToChat(p, MessageText);
                }
            }
            //Slack
            if (Settings.SlackConfig.DoNotifyWhenBaseAttacked && IsPlayerNotificationCooledDown(hitEntityOwnerID, NotificationType.SlackNotification, Settings.SlackConfig.NotificationCooldownInSeconds))
            {
                if (PercentHealthRemaining <= Settings.SlackConfig.ThresholdPercentageHealthRemaining)
                {
                    SendSlackNotification(player, MessageText);
                }
            }
            //Discord
            if (Settings.DiscordConfig.DoNotifyWhenBaseAttacked && IsPlayerNotificationCooledDown(hitEntityOwnerID, NotificationType.DiscordNotification, Settings.DiscordConfig.NotificationCooldownInSeconds))
            {
                if (PercentHealthRemaining <= Settings.DiscordConfig.ThresholdPercentageHealthRemaining)
                {
                    SendDiscordNotification(player, MessageText);
                }
            }
        }
コード例 #5
0
        private void OnEntityBuilt(Planner plan, GameObject go)
        {
            if (plan == null || go == null)
            {
                return;
            }

            string name = go.name;

            if (name == null || (name.Length != HighStoneWallName.Length && name.Length != HighWoodWallName.Length))
            {
                return;
            }
            else if (name != HighStoneWallName && name != HighWoodWallName)
            {
                return;
            }

            BasePlayer ownerPlayer = plan.GetOwnerPlayer();

            if (ownerPlayer == null)
            {
                return;
            }
            if (ownerPlayer.IsBuildingAuthed())
            {
                return;
            }

            BaseCombatEntity entity = go.GetComponent <BaseCombatEntity>();

            if (entity == null)
            {
                return;
            }

            float barricadeHealth = entity.MaxHealth() * barricadeHealthPercentage;

            entity.health = barricadeHealth;
            entity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);

            InvokeHandler.Invoke(entity, delegate
            {
                if (entity.health > barricadeHealth)
                {
                    return;
                }

                entity.Kill();
            }, decayTime);
        }
コード例 #6
0
 void OnLootEntity(BasePlayer player, BaseCombatEntity entity)
 {
     if (RepairOnLoot)
     {
         if (entity.LookupPrefab().name == "small_stash_deployed.prefab")
         {
             entity.health = entity.MaxHealth();
             if (Debug)
             {
                 Puts("Stash health restored");
             }
         }
     }
 }
コード例 #7
0
ファイル: HandyMan.cs プロジェクト: welcometopwn/oxideplugins
        object CanRepair(BaseCombatEntity entity, BasePlayer player, List <BaseCombatEntity> entities)
        {
            float num  = entity.MaxHealth() - entity.health;
            float num2 = num / entity.MaxHealth();
            var   list = entity.RepairCost(num2);

            if (list != null && list.Count > 0)
            {
                foreach (var ia in list)
                {
                    var items = player.inventory.FindItemIDs(ia.itemid);
                    int sum   = items.Sum(item => item.amount);

                    if (sum * repairMulti < ia.amount * repairMulti)
                    {
                        return(new KeyValuePair <string, float>(ia.itemDef.displayName.english, ia.amount));
                    }
                }
            }

            var privs = entities.Where(ent => ent != null && ent.net != null && !ent.IsDestroyed && ent is BuildingPrivlidge).Cast <BuildingPrivlidge>().ToList();

            if (privs.Count == 0)
            {
                return(true);
            }

            foreach (var priv in privs)
            {
                if (priv.Distance(entity) <= privDistance)
                {
                    return(!priv.AnyAuthed() || priv.IsAuthed(player));
                }
            }

            return(false); // player.CanBuild(new OBB(entity.transform, entity.bounds));
        }
コード例 #8
0
ファイル: NoEscape.cs プロジェクト: wilddip/oxideplugins
        object OnStructureRepair(BaseCombatEntity entity, BasePlayer player)
        {
            var result = CanDo("repair", player);

            if (result is string)
            {
                if (entity.health < entity.MaxHealth())
                {
                    return(null);
                }
                SendReply(player, result.ToString());
                return(true);
            }

            return(null);
        }
コード例 #9
0
ファイル: TurretNerf.cs プロジェクト: Cannabis-CFG/Oxide
        private object CanPickupEntity(BasePlayer player, BaseCombatEntity entity)
        {
            if (entity.name != autoTurretPrefab)
            {
                return(true);
            }
            var item = ItemManager.Create(entity.pickup.itemTarget, entity.pickup.itemCount);

            if (item.hasCondition)
            {
                item.conditionNormalized = entity.Health() / entity.MaxHealth() / 2;
            }
            player.GiveItem(item, BaseEntity.GiveItemReason.PickedUp);
            entity.OnPickedUp(item, player);
            entity.Kill();
            return(false);
        }
コード例 #10
0
        private object repairStructure(BaseCombatEntity entity, BasePlayer player)
        {
            if (entity.SecondsSinceAttacked <= (int)Config["nTimeSinceAttacked"])
            {
                return(null);
            }
            if (!(bool)Config["bChargeForRepairs"])
            {
                entity.health = entity.MaxHealth();
                entity.OnRepair();
                entity.SendNetworkUpdateImmediate(true);
                return(false);
            }

            float hp = entity.health;
            int   i  = 0;
            Dictionary <int, int> charge = new Dictionary <int, int>();

            while (hp < entity.MaxHealth())
            {
                if (i >= 30)
                {
                    Puts("Breaking loop -- Something went wrong");
                    break;
                }
                i += 1;
                float single  = 50f;
                float single1 = entity.MaxHealth() - hp;
                single1 = Mathf.Clamp(single1, 0f, single);
                float single2 = single1 / entity.MaxHealth();
                if (single2 == 0f)
                {
                    return(false);
                }
                List <ItemAmount> itemAmounts = entity.RepairCost(single2);
                if (itemAmounts == null)
                {
                    return(false);
                }
                float single3 = itemAmounts.Sum <ItemAmount>((ItemAmount x) => x.amount);
                if (single3 <= 0f)
                {
                    hp = entity.MaxHealth();
                }
                else
                {
                    float single4 = itemAmounts.Min <ItemAmount>((ItemAmount x) => Mathf.Clamp01((float)player.inventory.GetAmount(x.itemid) / x.amount));
                    if (single4 == 0f)
                    {
                        return(false);
                    }
                    int num = 0;
                    foreach (ItemAmount itemAmount in itemAmounts)
                    {
                        int num1 = Mathf.CeilToInt(single4 * itemAmount.amount);
                        int num2 = num1;
                        num = num + num2;
                        if (charge.ContainsKey(itemAmount.itemid))
                        {
                            charge[itemAmount.itemid] = charge[itemAmount.itemid] + num2;
                        }
                        else
                        {
                            charge.Add(itemAmount.itemid, num2);
                        }
                    }
                    float single5 = (float)num / (float)single3;
                    hp = hp + single1 * single5;
                    entity.OnRepair();
                }
            }
            foreach (KeyValuePair <int, int> item in charge)
            {
                ItemDefinition defs;
                defs = ItemManager.FindItemDefinition(item.Key);
                if (player.inventory.GetAmount(defs.itemid) < item.Value)
                {
                    return(null);
                }
            }
            foreach (KeyValuePair <int, int> item in charge)
            {
                player.inventory.Take(null, item.Key, item.Value);
                player.Command("note.inv", new object[] { item.Key, item.Value * -1 });
            }
            entity.health = entity.MaxHealth();
            entity.SendNetworkUpdateImmediate(true);
            return(false);
        }
コード例 #11
0
        /*
         * Name: CreateStackWall
         * Parameters: int amount, BaseEntity entity, BasePlayer player
         * Return: HashSet<ExternalWallLink>
         * Description: Creates the high external walls that stack on top of the first high external wall.
         */
        private HashSet <ExternalWallLink> CreateStackWall(int amount, BaseEntity entity, BasePlayer player)
        {
            // If the value of amount is less than 1 then set the value of amount to 1 else set the value of amount to the value of amount.
            amount = (amount < 1) ? 1 : amount;

            // Create an emply "list" that will contain ExternalWallLink(s).
            HashSet <ExternalWallLink> links = new HashSet <ExternalWallLink>();

            // If the configuration key "RequireMaterials" is set to true.
            if (this.configRequireMaterials == true)
            {
                // Find the item's definition for the type of high external wall that is being placed.
                ItemDefinition itemDefinition = ItemManager.FindItemDefinition(entity.ShortPrefabName);

                // Count how much high external walls the user has in their inventory.
                int canPlaceAmount = player.inventory.GetAmount(itemDefinition.itemid);

                // Subtract how much high external walls the user has in their inventory by one.
                canPlaceAmount = canPlaceAmount - 1;

                // If the amount of high external walls the user has in their inventory is less than one then return an empty list of ExternalWallLink(s).
                if (canPlaceAmount < 1)
                {
                    return(links);
                }

                // If the amount of high external walls the users has in their inventory is greater than the amount allowed to be placed then set the value of amount to the value of amount...
                // ...else set the value of amount to the value of how much high external walls the user has in their inventory.
                amount = (canPlaceAmount > amount) ? amount : canPlaceAmount;

                // Take # (based now the value of amount) of high external walls from the player.
                player.inventory.Take(new List <Item>(), itemDefinition.itemid, amount);
                // Notify the player of how much high external walls are being taken out of their inventory.
                player.Command("note.inv", itemDefinition.itemid, -amount);
            }

            // Create an emply ExternalWallLink.
            ExternalWallLink entityLink;

            // Loop until the value of index is greater than the value of amount plus one.
            for (int index = 1; index < amount + 1; index++)
            {
                // Create an high external wall.
                BaseEntity wall = GameManager.server.CreateEntity(entity.PrefabName, entity.transform.position + new Vector3(0f, 5.5f * (float)index, 0f), entity.transform.rotation, true);
                // Activate the high external wall game object.
                wall.gameObject.SetActive(true);
                // Spawn the high external wall game object.
                wall.Spawn();
                // Notify the server of the placement and rotation changes of the high external wall.
                wall.TransformChanged();

                // Get the BaseCombatEntity component of the high external wall.
                BaseCombatEntity combatEntity = wall.GetComponentInParent <BaseCombatEntity>();

                // If the component can be found.
                if (combatEntity != null)
                {
                    // Change the health of the high external wall to max health.
                    combatEntity.ChangeHealth(combatEntity.MaxHealth());
                }

                // Set the owner of the high external wall to the player.
                wall.OwnerID = player.userID;

                // Tell the server to to send a update to the players for the high external wall.
                wall.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);

                // Set the ExternalWallLink's game object to the high external wall's game object.
                entityLink = new ExternalWallLink(wall.gameObject);

                // Add the ExternalWallLink to the list of ExternalWallLink(s).
                links.Add(entityLink);
            }

            // Return the list of ExternalWallLink(s).
            return(links);
        }
コード例 #12
0
        private void DoRepair(BasePlayer player, BaseCombatEntity entity, PlayerRepairStats stats, bool noCost)
        {
            if (!entity.repair.enabled || entity.health == entity.MaxHealth())
            {
                return;
            }

            if (Interface.CallHook("OnStructureRepair", this, player) != null)
            {
                return;
            }

            if (entity.SecondsSinceAttacked <= 30f)
            {
                entity.OnRepairFailed(null, string.Empty);
                stats.RecentlyDamaged++;
                return;
            }

            float missingHealth    = entity.MaxHealth() - entity.health;
            float healthPercentage = missingHealth / entity.MaxHealth();

            if (missingHealth <= 0f || healthPercentage <= 0f)
            {
                entity.OnRepairFailed(null, string.Empty);
                return;
            }

            if (!noCost)
            {
                List <ItemAmount> itemAmounts = entity.RepairCost(healthPercentage);
                if (itemAmounts.Sum(x => x.amount) <= 0f)
                {
                    entity.health += missingHealth;
                    entity.SendNetworkUpdate();
                    entity.OnRepairFinished();
                    return;
                }

                if (_pluginConfig.RepairCostMultiplier != 1f)
                {
                    foreach (ItemAmount amount in itemAmounts)
                    {
                        amount.amount *= _pluginConfig.RepairCostMultiplier;
                    }
                }

                if (itemAmounts.Any(ia => player.inventory.GetAmount(ia.itemid) < (int)ia.amount))
                {
                    entity.OnRepairFailed(null, string.Empty);

                    foreach (ItemAmount amount in itemAmounts)
                    {
                        stats.MissingAmounts[amount.itemid] += (int)amount.amount;
                    }

                    stats.TotalCantAfford++;
                    return;
                }

                foreach (ItemAmount amount in itemAmounts)
                {
                    player.inventory.Take(null, amount.itemid, (int)amount.amount);
                    stats.AmountTaken[amount.itemid] += (int)amount.amount;
                }
            }

            entity.health += missingHealth;
            entity.SendNetworkUpdate();

            if (entity.health < entity.MaxHealth())
            {
                entity.OnRepair();
            }
            else
            {
                entity.OnRepairFinished();
            }

            stats.TotalSuccess++;
        }
コード例 #13
0
ファイル: HandyMan.cs プロジェクト: welcometopwn/oxideplugins
        // BaseCombatEntity
        public bool DoRepair(BaseCombatEntity entity, BasePlayer player)
        {
            if (!entity.repair.enabled)
            {
                return(false);
            }
            if (Interface.CallHook("OnStructureRepair", new object[]
            {
                entity,
                player
            }) != null)
            {
                return(false);
            }
            if (entity.SecondsSinceAttacked <= lastAttackLimit)
            {
                entity.OnRepairFailed();
                return(false);
            }
            float num  = entity.MaxHealth() - entity.Health();
            float num2 = num / entity.MaxHealth();

            if (num <= 0f || num2 <= 0f)
            {
                entity.OnRepairFailed();
                return(false);
            }
            var list = entity.RepairCost(num2);

            if (list == null || list.Count == 0)
            {
                return(false);
            }
            foreach (var ia in list)
            {
                ia.amount *= repairMulti;
            }
            float num3 = list.Sum(x => x.amount);

            if (num3 > 0f)
            {
                float num4 = list.Min(x => Mathf.Clamp01((float)player.inventory.GetAmount(x.itemid) / x.amount));
                num4 = Mathf.Min(num4, 50f / num);
                if (num4 <= 0f)
                {
                    entity.OnRepairFailed();
                    return(false);
                }
                int num5 = 0;
                foreach (var current in list)
                {
                    int amount = Mathf.CeilToInt(num4 * current.amount);
                    num5 += player.inventory.Take(null, current.itemid, amount);
                }

                float num7 = (float)num5 / num3;
                entity.health += num * num7;
                entity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
            }
            else
            {
                entity.health += num;
                entity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
            }
            if (entity.health >= entity.MaxHealth())
            {
                entity.OnRepairFinished();
            }
            else
            {
                entity.OnRepair();
            }

            return(true);
        }
コード例 #14
0
ファイル: RepairTool.cs プロジェクト: rustmy/rustylife
 public float GetRepairFraction(BaseCombatEntity blockToRepair)
 {
     return(1f - blockToRepair.health / blockToRepair.MaxHealth());
 }