Ejemplo 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);
        }