Ejemplo n.º 1
0
        /** Purchase item, gives to currently selected party memeber. */
        public bool PurchaseItem(MDRItem item)
        {
            MDRCharacter buyer = CoM.Party.Selected;

            if (buyer == null)
            {
                return(false);
            }

            if (CoM.Party.Gold < SellPrice(item))
            {
                return(false);
            }

            // do the transaction
            if (buyer.GiveItem(MDRItemInstance.Create(item)))
            {
                CoM.Party.DebitGold(SellPrice(item), buyer);
                SubtractQuantity(item, 1);
                return(true);
            }
            else
            {
                CoM.PostMessage(buyer + " does not have enough space for " + item);
                return(false);
            }
        }
Ejemplo n.º 2
0
 /** Override can send to notify player the item is cursed */
 public override bool CanSend(IDragDrop destination)
 {
     if ((DataLink != null) && (!(destination is GuiInspectionSlot)) && DataLink.IsEquipSlot && containsCursedItem())
     {
         CoM.PostMessage("This item is cursed!");
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
        /**
         * Causes detials in the perceived tile to be copied across from the actual tile, will also log messages
         * decribing the new features discovered.  Returns true if any update occured
         *
         * @returns if any changes where made.
         */
        private bool detectSquare(FieldRecord perceivedTile, FieldRecord actualTile, string message, MDRCharacter character)
        {
            string detailName = "";

            if (perceivedTile.FaceNorth != actualTile.FaceNorth)
            {
                detailName += "a face north, ";
            }
            if (perceivedTile.FaceEast != actualTile.FaceEast)
            {
                detailName += "a face east, ";
            }
            if (perceivedTile.FaceWest != actualTile.FaceWest)
            {
                detailName += "a face west, ";
            }
            if (perceivedTile.FaceSouth != actualTile.FaceSouth)
            {
                detailName += "a face south, ";
            }

            if (perceivedTile.Antimagic != actualTile.Antimagic)
            {
                detailName += "an anti-magic, ";
            }
            if (perceivedTile.Rotator != actualTile.Rotator)
            {
                detailName += "a rotator, ";
            }
            if (perceivedTile.Extinguisher != actualTile.Extinguisher)
            {
                detailName += "an extinguisher, ";
            }
            if (perceivedTile.Stud != actualTile.Stud)
            {
                detailName += "a stud, ";
            }

            if (detailName != "")
            {
                CoM.PostMessage(message, CoM.Format(character), detailName.TrimEnd(new char[] { ' ', ',' }));
            }

            perceivedTile.FaceNorth    = actualTile.FaceNorth;
            perceivedTile.FaceEast     = actualTile.FaceEast;
            perceivedTile.FaceWest     = actualTile.FaceWest;
            perceivedTile.FaceSouth    = actualTile.FaceSouth;
            perceivedTile.Antimagic    = actualTile.Antimagic;
            perceivedTile.Rotator      = actualTile.Rotator;
            perceivedTile.Extinguisher = actualTile.Extinguisher;
            perceivedTile.Stud         = actualTile.Stud;

            return(detailName != "");
        }
Ejemplo n.º 4
0
 /** Writes contents of library to log */
 public void WriteToLog(bool logToScreen = false)
 {
     foreach (T obj in DataList)
     {
         Trace.Log(obj.LongDescription());
         if (logToScreen)
         {
             CoM.PostMessage(obj.LongDescription());
         }
     }
 }
Ejemplo n.º 5
0
 /** Writes names of library entrys to log */
 public void ListToLog(bool logToScreen = false)
 {
     foreach (T obj in DataList)
     {
         Trace.Log(obj.ToString());
         if (logToScreen)
         {
             CoM.PostMessage(obj.ToString());
         }
     }
 }
Ejemplo n.º 6
0
        /**
         * Attempts to use or equip the item stored in this container.
         * Equipable items will be equiped.  Usable items will be used
         */
        protected void UseOrEquipItem()
        {
            if (DataLink.IsEmpty)
            {
                return;
            }

            MDRItemInstance itemInstance = DataLink.ItemInstance;

            //stub: slots should know the character they're associated with */
            MDRCharacter character = CoM.Party.Selected;

            if (!itemInstance.IDLevel.CanUse)
            {
                CoM.PostMessage("{0} must be more identified before it can be used.", CoM.Format(itemInstance));
                return;
            }

            if (itemInstance.Item.Usable)
            {
                // first can this item be activated?
                string reason = itemInstance.GetCanNotUseReason(character);
                if (reason == "")
                {
                    if (itemInstance.RemainingCharges <= 0)
                    {
                        CoM.PostMessage("Item is out of charges.");
                    }
                    else
                    {
                        itemInstance.Use(character);
                    }
                }
                else
                {
                    CoM.PostMessage(reason);
                }
            }
            else
            {
                // otherwise try equiping it
                string reason = itemInstance.GetCanNotEquipReason(character);
                if (reason == "")
                {
                    character.EquipItem(DataLink);
                }
                else
                {
                    CoM.PostMessage(reason);
                }
            }
        }
Ejemplo n.º 7
0
        /** Applies healing. */
        protected void ApplyHealing(SpellResult info)
        {
            Util.Assert(HealingSpell, "Tried casting a non healing spell as a healing spell.");

            Util.Assert(info.Target != null, "Target for healing spell must not be null.");

            if (info.Target.IsDead)
            {
                CoM.PostMessage("Can not cast {0} on {1}, they are dead.", info.Spell, info.Target);
                return;
            }

            int healing = CalculateSpellHealing(info.Caster, info.Target);

            // caclulate the amount of healing done
            info.HealingDone = info.Target.ReceiveHealing(healing);
            info.DidCast     = true;
        }
Ejemplo n.º 8
0
        /** Checks if party is standing on any traps and applied changes. */
        private void checkTraps()
        {
            if (CurrentTile.Pit)
            {
                int numberOfCharactersWhoFell = 0;
                foreach (MDRCharacter character in this)
                {
                    if (character.IsDead)
                    {
                        continue;
                    }
                    if (GameRules.FallRoll(character))
                    {
                        int damage = GameRules.CalculatePitDamage(character);

                        character.ReceiveDamage(damage);

                        string message = character.IsDead ? "{0} fell down a pit, receiving {1} damage, and died." : "{0} fell down a pit receiving {1} damage.";
                        CoM.PostMessage(message, CoM.Format(character), CoM.Format(damage));
                        numberOfCharactersWhoFell++;
                    }
                    else
                    {
                        CoM.PostMessage("{0} avoided the pit.", CoM.Format(character));
                    }
                }
                if (numberOfCharactersWhoFell > 0)
                {
                    SoundManager.Play("OLDFX_FALL");
                }
            }

            if (CurrentTile.Rotator)
            {
                int turns = Util.Roll(4) + 4;

                DelayedDelegates.Add(delegate {
                    for (int lp = 0; lp < turns; lp++)
                    {
                        TurnLeft();
                    }
                    CoM.PostMessage("Party hit a rotator.");
                }, 0.1f);
            }

            if (CurrentTile.Water)
            {
                SoundManager.Play("OLDFX_WADE");
            }
            else
            {
                foreach (MDRCharacter character in this)
                {
                    character.TimeInWater = 0;
                }
            }

            if (CurrentTile.FaceEast)
            {
                Facing = Direction.EAST;
            }
            if (CurrentTile.FaceWest)
            {
                Facing = Direction.WEST;
            }
            if (CurrentTile.FaceSouth)
            {
                Facing = Direction.SOUTH;
            }
            if (CurrentTile.FaceNorth)
            {
                Facing = Direction.NORTH;
            }

            if (CurrentTile.Chute)
            {
                ChuteTrapInfo chute = Map.GetChutAt(LocationX, LocationY);
                if (chute == null)
                {
                    Trace.LogWarning("No chute found at party's current location.");
                }
                else
                {
                    if ((Depth + chute.DropDepth) > Dungeon.Floors)
                    {
                        CoM.PostMessage("This chute doesn't seem to go anywhere.  You can't help but feel fortunate.");
                    }
                    else
                    {
                        int numberOfCharactersWhoFell = 0;
                        foreach (MDRCharacter character in this)
                        {
                            if (character.IsDead)
                            {
                                continue;
                            }
                            if (GameRules.FallRoll(character))
                            {
                                numberOfCharactersWhoFell++;
                            }
                        }

                        if (numberOfCharactersWhoFell == LivingMembers)
                        {
                            Depth += chute.DropDepth;
                            CoM.PostMessage("Party fell down a chute");
                            SoundManager.Play("OLDFX_FALL");
                        }
                        else
                        {
                            CoM.PostMessage("Party avoided falling down a chute");
                        }
                    }
                }
            }

            if (CurrentTile.Teleporter)
            {
                TeleportTrapInfo teleport = Map.GetTeleportAt(LocationX, LocationY);
                if (teleport == null)
                {
                    Trace.LogWarning("No teleport found at party's current location.");
                }
                else
                {
                    if (teleport.DestFloor > Dungeon.Floors)
                    {
                        CoM.PostMessage("The teleport trap fizzes, but doesn't seem to do anything.");
                        return;
                    }

                    int destinationX     = teleport.DestX;
                    int destinationY     = teleport.DestY;
                    int destinationFloor = teleport.DestFloor == 0 ? Depth : teleport.DestFloor;

                    if (teleport.IsRandom())
                    {
                        int trys = 0;
                        while (true)
                        {
                            destinationX = Util.Roll(30);
                            destinationY = Util.Roll(30);
                            if (!Map.GetField(destinationX, destinationY).Rock)
                            {
                                break;
                            }
                            trys++;
                            if (trys > 999)
                            {
                                Trace.LogWarning("Could not find safe place to teleport character to.");
                                return;
                            }
                        }
                    }

                    SoundManager.Play("OLDFX_TELEPORT");

                    SetLocation(destinationX, destinationY, destinationFloor, Facing);

                    Trace.Log("Teleporting characters to " + destinationX + "," + destinationY);
                    CoM.PostMessage("Party hit a teleporter");
                }
            }
        }
Ejemplo n.º 9
0
        /** Updates the explored map to reveal the tile the party is standing on. */
        private void updateExploredMap()
        {
            var origionalValue = PerceivedTile.Value;

            bool secretDiscovered = false;

            if (PerceivedTile != null)
            {
                var character = PerceptionCharacter;

                PerceivedTile.Explored   = true;
                PerceivedTile.Water      = CurrentTile.Water;
                PerceivedTile.Pit        = CurrentTile.Pit;
                PerceivedTile.StairsUp   = CurrentTile.StairsUp;
                PerceivedTile.StairsDown = CurrentTile.StairsDown;
                PerceivedTile.Teleporter = CurrentTile.Teleporter;
                PerceivedTile.Dirt       = CurrentTile.Dirt;
                PerceivedTile.Rock       = CurrentTile.Rock;
                PerceivedTile.Chute      = CurrentTile.Chute;
                PerceivedTile.Grass      = CurrentTile.Grass;

                bool blind = false;
                if (!blind)
                {
                    // copy walls, but leave secrets alone
                    for (int lp = 0; lp < 4; lp++)
                    {
                        WallRecord wall                = new WallRecord();
                        var        actualWallRecord    = CurrentTile.getWallRecord(lp);
                        var        perceivedWallRecord = PerceivedTile.getWallRecord(lp);

                        if (actualWallRecord.Secret)
                        {
                            wall.Type = perceivedWallRecord.Secret ? WallType.Secret : WallType.Wall;
                        }
                        else
                        {
                            wall.Type = actualWallRecord.Type;
                        }

                        if (actualWallRecord.Secret && !perceivedWallRecord.Secret)
                        {
                            if (GameRules.PerceptionRoll(character, 15 + (Depth * 5)))
                            {
                                CoM.PostMessage("{0} discovered a secret door.", CoM.Format(character));
                                SoundManager.Play("OLDFX_FOUND");
                                wall.Type        = WallType.Secret;
                                secretDiscovered = true;
                            }
                        }

                        PerceivedTile.setWallRecord(lp, wall);
                    }
                }

                if (PerceivedTile.GroundValue != CurrentTile.GroundValue)
                {
                    // roll to see if we detect the difference or not
                    if (GameRules.PerceptionRoll(character, 10 + (Depth * 2)))
                    {
                        detectSquare(PerceivedTile, CurrentTile, "{0} detected that the party is standing on {1} square.", character);
                    }
                    else
                    {
                        if (GameRules.PerceptionRoll(character, (Depth)))
                        {
                            CoM.PostMessage("{0} detects something strange about this place.", CoM.Format(character));
                        }
                    }
                }
            }

            bool tileChanged = origionalValue != PerceivedTile.Value || secretDiscovered;

            if (CoM.GraphicsLoaded && tileChanged)
            {
                CoM.Instance.RefreshMapTile(LocationX, LocationY);
            }
        }
Ejemplo n.º 10
0
    private void ProcessCheatKeys()
    {
        if (!Input.GetKey(KeyCode.LeftShift))
        {
            return;
        }

        if (Input.GetKeyUp(KeyCode.L))
        {
            Party.Selected.CurrentMembership.XP += Party.Selected.CurrentMembership.ReqXP;
            Party.Selected.GainLevel();
        }

        if (Input.GetKeyUp(KeyCode.K))
        {
            Party.Selected.ReceiveDamage(20);
        }

        if (Input.GetKeyUp(KeyCode.M))
        {
            Party.ExploredMap.Clear();
            if (CoM.Instance.DungeonState != null)
            {
                CoM.Instance.DungeonState.AutoMap.Repaint();
            }
        }


        if (Input.GetKeyUp(KeyCode.O))
        {
            PartyController.Instance.EnableDoorOpener = !PartyController.Instance.EnableDoorOpener;
        }

        //stub: remove or use for testing

        /*
         * if (Input.GetKeyUp(KeyCode.H)) {
         *      var spell = CoM.Spells.ByName("Minor Heal");
         *      var result = spell.Cast(Party.Selected, Party.Selected);
         *      CoM.PostMessage(result.Formatted);
         * } */

        // give cursed item
        if (Input.GetKeyUp(KeyCode.C))
        {
            Party.Selected.GiveItem(MDRItemInstance.Create(CoM.Items.ByName("Ball and Chain")));
        }

        // uncurse all items
        if (Input.GetKeyUp(KeyCode.U))
        {
            CoM.PostMessage("Uncursing all equiped items");
            foreach (MDRItemSlot item in Party.Selected.Equiped)
            {
                if (!item.IsEmpty)
                {
                    item.ItemInstance.Cursed = false;
                }
            }
        }

        if (Input.GetKeyUp(KeyCode.M))
        {
            CoM.PostMessage("fish and chips " + Time.frameCount);
        }
        if (Input.GetKeyUp(KeyCode.N))
        {
            Engine.PostNotification("Fish and chips is a long sentance that takes 3 lines:" + Time.frameCount, Party.Selected.Portrait);
        }
    }