Esempio n. 1
0
        public override bool Hurt(float damage, string cause, object aggressor, bool finishable = false, bool leaveCorpse = true)
        {
            if (AutoTravelling)
            {
                NoxicoGame.AddMessage(i18n.Format("autotravelstop"));
                AutoTravelling = false;
            }

            if (Character.HasItemEquipped("eternitybrooch"))
            {
                var brooch = Character.GetEquippedItemBySlot("neck");                 //can assume the neck slot has the brooch.
                var today  = NoxicoGame.InGameTime.DayOfYear;
                if (!brooch.HasToken("lastTrigger"))
                {
                    brooch.AddToken("lastTrigger", today - 2);
                }
                if (Math.Abs(brooch.GetToken("lastTrigger").Value - today) >= 2 && Character.Health - damage <= 0)
                {
                    brooch.GetToken("lastTrigger").Value = today;
                    NoxicoGame.AddMessage(i18n.GetString("eternitybrooched"));
                    Character.Health = Character.MaximumHealth;
                    Reposition();
                    return(false);
                }
            }

            var dead = base.Hurt(damage, cause, aggressor, finishable);

            if (dead)
            {
                if (aggressor != null && aggressor is BoardChar)
                {
                    var aggChar  = ((BoardChar)aggressor).Character;
                    var relation = Character.Path("ships/" + aggChar.ID);
                    if (relation == null)
                    {
                        relation = new Token(aggChar.ID);
                        Character.Path("ships").Tokens.Add(relation);
                    }
                    relation.AddToken("killer");
                    if (aggChar.HasToken("stolenfrom"))
                    {
                        var myItems     = Character.GetToken("items").Tokens;
                        var hisItems    = aggChar.GetToken("items").Tokens;
                        var stolenGoods = myItems.Where(t => t.HasToken("owner") && t.GetToken("owner").Text == aggChar.ID).ToList();
                        foreach (var item in stolenGoods)
                        {
                            hisItems.Add(item);
                            myItems.Remove(item);
                        }
                        aggChar.GetToken("stolenfrom").Name = "wasstolenfrom";
                        aggChar.RemoveToken("hostile");
                    }
                }

                if (Lives == 0)
                {
                    Character.AddToken("gameover");
                    NoxicoGame.AddMessage(i18n.GetString("gameover_title"), Color.Red);
                    //var playerFile = Path.Combine(NoxicoGame.SavePath, NoxicoGame.WorldName, "player.bin");
                    //File.Delete(playerFile);
                    var world = string.Empty;
                    if (NoxicoGame.WorldName != "<Testing Arena>")
                    {
                        world = System.IO.Path.Combine(NoxicoGame.SavePath, NoxicoGame.WorldName);
                    }
                    NoxicoGame.Sound.PlayMusic("set://Death");
                    NoxicoGame.InGame = false;
                    var c = i18n.GetString(cause + "_player");
                    if (c[0] == '[')
                    {
                        c = i18n.GetString(cause);
                    }
                    MessageBox.Ask(
                        i18n.Format("youdied", c),
                        () =>
                    {
                        Character.CreateInfoDump();
                        if (NoxicoGame.WorldName != "<Testing Arena>")
                        {
                            Directory.Delete(world, true);
                        }
                        NoxicoGame.HostForm.Close();
                    },
                        () =>
                    {
                        if (NoxicoGame.WorldName != "<Testing Arena>")
                        {
                            Directory.Delete(world, true);
                        }
                        NoxicoGame.HostForm.Close();
                    }
                        );
                }
                else
                {
                    Respawn();
                }
            }
            return(dead);
        }
Esempio n. 2
0
        public bool Equip(Character character, Token item)
        {
            /*
             * if rings and character is quadruped, error out.
             * if required slots have covering slots
             *      check for target slot's reachability.
             *      if unreachable, try to temp-remove items in covering slots, recursively.
             *      if still unreachable, error out.
             * if required slots are taken
             *      try to unequip the items in those slots, recursively.
             *      if required slots are still taken, error out;
             *      else, mark the item as equipped.
             * replace each temp-removed item whose required slots are still free.
             */
            var equip      = this.GetToken("equipable");
            var tempRemove = new Stack <Token>();

            //var items = character.GetToken("items");

            //TODO: make full quadrupeds equip weapons in their mouth instead of the hands they don't have.
            //This means they can carry only ONE weapon at a time, and maybe not be able to converse until unequipped.
            if ((equip.HasToken("hands") || equip.HasToken("ring")) && (character.HasToken("quadruped")))
            {
                throw new ItemException(i18n.Format("cannot_equip_no_hands", this.ToString(item, true, false)));
            }

            if (equip.HasToken("hand"))
            {
                CheckHands(character, "hand");
            }
            else if (equip.HasToken("ring"))
            {
                CheckHands(character, "ring");
            }
            if (equip.HasToken("pants") || equip.HasToken("underpants") || equip.HasToken("shoes") || equip.HasToken("socks"))
            {
                CheckPants(character, equip);
            }
            if (character.HasToken("snaketail") && (equip.HasToken("pants") || equip.HasToken("underpants")))
            {
                throw new ItemException(i18n.Format("cannot_equip_no_legs", this.ToString(item, true, false)));
            }

            //lol
            foreach (var nonLayeredSlot in new[] { "socks", "hat", "mask", "goggles", "neck" })
            {
                if (equip.HasToken(nonLayeredSlot))
                {
                    var currentNonLayeredItem = character.GetEquippedItemBySlot(nonLayeredSlot);
                    if (currentNonLayeredItem != null)
                    {
                        currentNonLayeredItem.Unequip(character);
                    }
                }
            }

            foreach (var t in equip.Tokens)
            {
                if (t.Name == "underpants" && (!TempRemove(character, tempRemove, "pants") || !TempRemove(character, tempRemove, "underpants")))
                {
                    return(false);
                }
                else if (t.Name == "undershirt" && (!TempRemove(character, tempRemove, "shirt") || !TempRemove(character, tempRemove, "undershirt")))
                {
                    return(false);
                }
                else if (t.Name == "shirt" && (!TempRemove(character, tempRemove, "shirt") || !TempRemove(character, tempRemove, "jacket")))
                {
                    return(false);
                }
                else if (t.Name == "jacket" && (!TempRemove(character, tempRemove, "cloak") || !TempRemove(character, tempRemove, "jacket")))
                {
                    return(false);
                }
                else if (t.Name == "socks" && (!TempRemove(character, tempRemove, "shoes") || !TempRemove(character, tempRemove, "socks")))
                {
                    return(false);
                }
            }

            var succeed = true;

            if (!this.OnEquip.IsBlank())
            {
                succeed = Convert.ToBoolean(RunScript(item, this.OnEquip, character, null, null));
            }
            if (succeed)
            {
                item.AddToken("equipped");
            }

            if (this.HasToken("timer") && !this.OnTimer.IsBlank() && !item.HasToken("timer"))
            {
                item.AddToken("timer").Value = (this.GetToken("timer").Value == 0) ? 60 : this.GetToken("timer").Value;
                item.GetToken("timer").Text  = NoxicoGame.InGameTime.ToBinary().ToString();
            }

            character.RecalculateStatBonuses();
            character.CheckHasteSlow();

            //Difficult bit: gotta re-equip tempremovals without removing the target item all over. THAT WOULD BE QUITE BAD.
            return(succeed);
        }