/// <summary> /// /// /// </summary> //Player-only interfaces public void DropDialogue() { int dropCoordX = owner.CoordX; int dropcoordY = owner.CoordY; if (BodyCarrying != null) { DropBody(); return; } List <Item> dropped = MultipleItemSelectionMenu("drop", Backpack); for (int i = 0; i < dropped.Count; i++) { if (owner is Player) { Log.AddLine("You dropped the " + dropped[i].DisplayName); } dropped[i].CoordX = dropCoordX; dropped[i].CoordY = dropcoordY; owner.Timing.AddActionTime(TimeCost.DropItemCost(dropped[i])); World.AllItemsOnFloor.Add(dropped[i]); Backpack.Remove(dropped[i]); //if (dropped.Count == 1) break; } Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray; }
public bool TryPickUpItem(Item picked) { if (picked is UnconsciousBody || picked is Corpse) { if (BodyCarrying != null) { if (owner is Player) { Log.AddLine("You're already carrying a body!"); } //_DEBUG.AddDebugMessage("Already carrying!"); return(false); } else { BodyCarrying = picked; } } else { bool stacked = false; if (picked.isStackable) { if (Ready != null) { if (Ready.isEqualTo(picked)) { Ready.Quantity += picked.Quantity; stacked = true; } } else if (picked is Ammunition) { Ready = (Ammunition)picked; stacked = true; } if (!stacked) { foreach (Item itm in Backpack) { if (itm.isEqualTo(picked)) { itm.Quantity += picked.Quantity; stacked = true; break; } } } } if (!stacked) { Backpack.Add(picked); } } owner.Timing.AddActionTime(TimeCost.PickUpCost(picked)); return(true); }
public bool TryMoveForward() //move where this unit looks. returns true if the unit has moved. { if (World.IsPassable(CoordX + lookX, CoordY + lookY)) { Timing.AddActionTime(TimeCost.MoveCost(this)); CoordX += lookX; CoordY += lookY; return(true); } return(false); }
public static void MeleeAttack(Unit attacker, Unit victim) { Weapon attackerWeapon = attacker.Inv.Wielded; if (attackerWeapon != null) { if (!attackerWeapon.targetInMeleeRange(attacker.CoordX, attacker.CoordY, victim.CoordX, victim.CoordY)) { //Zomg error _DEBUG.AddDebugMessage("ERROR: attempt to melee from non-melee range."); } attacker.Timing.AddActionTime(TimeCost.MeleeAttackCost(attacker)); int finalDamage = CalculateMeleeDamage(attacker, victim); bool victimStabbed = false; if (attacker.Inv.Wielded.TypeOfMeleeDamage == Weapon.MeleeDamageTypes.Stab && victim.IsUnaware()) { finalDamage *= 6; //zomg Log.AddOneFromList(StringFactory.AttackerStabsVictim(attacker, victim)); victimStabbed = true; } else { if (attacker is Player) { Log.AddLine("You hit " + victim.Name + " with your " + attacker.Inv.Wielded.DisplayName + "!"); } else { Log.AddLine(attacker.Name + " hits " + victim.Name + " with the " + attacker.Inv.Wielded.DisplayName + "!"); } } victim.Hitpoints -= finalDamage; if (attacker is Player) { _DEBUG.AddDebugMessage(" " + finalDamage.ToString() + " damage"); } if (victim is Player) { Gameover.KilledBy = attacker.Name; if (victim.Hitpoints < victim.GetMaxHitpoints() / 3 || victim.Hitpoints < 3) { Log.AddAlertMessage("!!LOW HITPOINT WARNING!!"); } } if (victimStabbed) { Log.AddOneFromList(StringFactory.stabbedVictimReacts(victim)); } } }
public bool tryReloadWeapon() { if (Wielded.IsReloadable && Ready != null) { if (Wielded.TryReload(Ready)) { owner.Timing.AddActionTime(TimeCost.ReloadCost(owner)); return(true); } } return(false); }
void peepDialogue() { Log.AddLine("Peep in which direction?"); ConsoleKeyInfo keyPressed = Console.ReadKey(true); KeyToVector.ProcessInput(keyPressed); int peepX = CoordX + KeyToVector.x, peepY = CoordY + KeyToVector.y; if (peepX == CoordX && peepY == CoordY) { int randomMessageNumber = MyRandom.getRandomInt(3); switch (randomMessageNumber) { case 0: Log.AddLine("You feel SO introversive for a moment"); break; case 1: Log.AddLine("You peep yourself. So interesting"); break; case 2: Log.AddLine("If you wanna, hm, look at yourself, get a room, please."); break; } return; } //don't peep through walls anymore! :D if (World.IsPassable(peepX, peepY) || World.IsDoorPresent(peepX, peepY)) { isPeeping = true; lastPeepX = peepX; lastPeepY = peepY; WorldRendering.drawInCircleFOV(peepX, peepY, visibilityRadius); WorldRendering.drawUnitsInCircle(peepX, peepY, visibilityRadius); this.Draw(); Console.ForegroundColor = ConsoleColor.Gray; Timing.AddActionTime(TimeCost.CloseDoorCost(this)); Log.ReplaceLastLine("You carefully peep in that direction... Press space or esc to stop"); keyPressed = Console.ReadKey(true); if (keyPressed.Key == ConsoleKey.Spacebar || keyPressed.Key == ConsoleKey.Escape) { isPeeping = false; Log.ReplaceLastLine("You carefully peep in that direction..."); } } else { Log.ReplaceLastLine("You try to peep through this, but in vain."); } }
protected void moveForwardOrOpen() { if (World.IsDoorPresent(CoordX + lookX, CoordY + lookY)) { if (World.TryUnlockDoor(CoordX + lookX, CoordY + lookY, Inv.GetAllKeys)) { Timing.AddActionTime(TimeCost.OpenDoorCost(this)); } } else { TryMoveForward(); } }
public void MoveOrOpenOrAttack(int x, int y) //-1 or 0 or 1 for x and y { if (World.IsDoorPresent(CoordX + x, CoordY + y)) { if (World.TryUnlockDoor(CoordX + x, CoordY + y, Inv.GetAllKeys)) { Timing.AddActionTime(TimeCost.OpenDoorCost(this)); Log.AddLine("You have unlocked the door with your key."); return; } if (World.TryOpenDoor(CoordX + x, CoordY + y)) { Timing.AddActionTime(TimeCost.OpenDoorCost(this)); Log.AddLine("You opened the door."); return; } } if (World.IsPassable(CoordX + x, CoordY + y)) { CoordX += x; CoordY += y; Timing.AddActionTime(TimeCost.MoveCost(this)); if (World.isItemPresent(CoordX, CoordY)) { List <Item> list = World.getItemListAt(CoordX, CoordY); int numberOfItemsOnFloor = list.Count(); if (numberOfItemsOnFloor > 1) { Log.AddLine("You see here: " + list[0].DisplayName + " and " + (numberOfItemsOnFloor - 1).ToString() + " more items"); } else { Log.AddLine("You see here: " + list[0].DisplayName); } } return; } if (World.isActorPresent(CoordX + x, CoordY + y)) { Actor attacked = World.getActorAt(CoordX + x, CoordY + y); Attack.MeleeAttack(this, attacked); } else if (!World.IsPassable(CoordX + x, CoordY + y)) { Log.AddLine("Locked! You need a key."); } //World.Redraw(CoordX-x, CoordY-y); }
void turnToRandomPassableDirection() //turn to random direction which is passable { int newLookX, newLookY; int tries = 0; do { newLookX = MyRandom.getRandomInt(-1, 2); newLookY = MyRandom.getRandomInt(-1, 2); if (tries > 50) { break; //this is } tries++; //a quite dirty workaround } while ((newLookX == 0 && newLookY == 0) || !World.IsPassable(CoordX + newLookX, CoordY + newLookY)); turnToDirection(newLookX, newLookY); Timing.AddActionTime(TimeCost.GuardWait(this)); }
public void DropBody() //OF COURSE it's not final! { int dropCoordX = owner.CoordX; int dropcoordY = owner.CoordY; Item dropped; if (BodyCarrying != null) { if (owner is Player) { Log.AddLine("You dropped the " + BodyCarrying.DisplayName + " from your shoulder."); } dropped = BodyCarrying; dropped.CoordX = dropCoordX; dropped.CoordY = dropcoordY; owner.Timing.AddActionTime(TimeCost.DropItemCost(dropped)); World.AllItemsOnFloor.Add(dropped); BodyCarrying = null; } }
void closeDoorDialogue() { Log.AddLine("Close door in which direction?"); ConsoleKeyInfo keyPressed = Console.ReadKey(true); KeyToVector.ProcessInput(keyPressed); int doorX = CoordX + KeyToVector.x, doorY = CoordY + KeyToVector.y; if (doorX == CoordX && doorY == CoordY) { int randomMessageNumber = MyRandom.getRandomInt(3); switch (randomMessageNumber) { case 0: Log.AddLine("Wow. You costumed like a door this Halloween?"); break; case 1: Log.AddLine("You have almost closed yourself, but suddenly remembered that you're not a door."); break; case 2: Log.AddLine("Okay... Try another time"); break; } return; } if (World.TryCloseDoor(doorX, doorY)) { Timing.AddActionTime(TimeCost.PeepCost(this)); Log.ReplaceLastLine("You carefully closed the door."); } else { Log.ReplaceLastLine("You tried to close this, but something went wrong..."); } }
void strangleDialogue() { Log.AddLine("Grab in which direction?"); ConsoleKeyInfo keyPressed = Console.ReadKey(true); KeyToVector.ProcessInput(keyPressed); int strangleX = CoordX + KeyToVector.x, strangleY = CoordY + KeyToVector.y; if (strangleX == CoordX && strangleY == CoordY) { int randomMessageNumber = MyRandom.getRandomInt(3); switch (randomMessageNumber) { case 0: Log.AddLine("Wanna strangle yourself huh?"); break; case 1: Log.AddLine("Suicide will not help with your mission."); break; case 2: Log.AddLine("If you wanna touch yourself, get a room, please."); break; } return; } if (World.isActorPresent(strangleX, strangleY)) { Attack.Strangle(this, World.getActorAt(strangleX, strangleY)); Timing.AddActionTime(TimeCost.StrangleCost(this)); } else { Log.AddLine("There's nobody here!"); } }
public static void RangedAttack(Unit attacker, Unit victim) { Weapon attackerWeapon = attacker.Inv.Wielded; if (attackerWeapon.Range > 1) { attacker.Timing.AddActionTime(TimeCost.RangedAttackCost(attacker)); if (!attackerWeapon.TryConsumeAmmo()) { if (attacker is Player) { Log.ReplaceLastLine("Click!"); } else { Log.AddLine(attacker.Name + "'s " + attackerWeapon.DisplayName + " clicks!"); } return; } int damage = CalculateRangedDamage(attacker, victim); victim.Hitpoints -= damage; if (attacker is Player) { Log.AddLine("You shot the " + victim.Name + " with your " + attacker.Inv.Wielded.DisplayName + "!"); } else { Log.AddLine(attacker.Name + " shoots at " + victim.Name + " with the " + attacker.Inv.Wielded.DisplayName + "!"); } Console.ForegroundColor = ConsoleColor.Yellow; WorldRendering.DrawTraversingBullet(attacker.CoordX, attacker.CoordY, victim.CoordX, victim.CoordY, '*'); } else { _DEBUG.AddDebugMessage("ERROR: attempt to shoot from non-ranged weapon!"); } }
public void handleKeys(ConsoleKeyInfo keyPressed) { if (isPeeping) { Timing.AddActionTime(TimeCost.ContinuePeepCost(this)); ContinuePeep(keyPressed); return; } //MOVING/WAITING if (keyPressed.Key == ConsoleKey.NumPad5) //skip turn { Timing.AddActionTime(TimeCost.SkipTurnCost(this)); return; } KeyToVector.ProcessInput(keyPressed); if (KeyToVector.ProperButtonPressed) { MoveOrOpenOrAttack(KeyToVector.x, KeyToVector.y); } //ACTIONS if (keyPressed.Key == ConsoleKey.D1) { seeTheStats(); } if (keyPressed.Key == ConsoleKey.C) //close door { closeDoorDialogue(); } if (keyPressed.Key == ConsoleKey.D) //drop an item { Inv.DropDialogue(); } if (keyPressed.Key == ConsoleKey.F) //fire current weapon { shootDialogue(); } if (keyPressed.Key == ConsoleKey.G) //grab (pick up) an item { Inv.PickupDialogue(); } if (keyPressed.Key == ConsoleKey.I) //show inventory { Inv.ShowInventory(); } if (keyPressed.Key == ConsoleKey.P) //peep { peepDialogue(); } if (keyPressed.Key == ConsoleKey.S) //strangle { strangleDialogue(); } if (keyPressed.Key == ConsoleKey.W) //wield a weapon { Inv.WieldDialogue(); } if (keyPressed.Key == ConsoleKey.Q) //ready the ammo { Inv.ReadyAmmoDialogue(); } if (keyPressed.Key == ConsoleKey.R) //reload a gun { Inv.ReloadDialogue(); } //TODO! }
protected void turnToDirection(int x, int y) { lookX = x; lookY = y; Timing.AddActionTime(TimeCost.TurningCost(this)); }