|
2 | 2 |
|
3 | 3 | interface |
4 | 4 |
|
| 5 | +uses BearLibItems, uCommon, uMap; |
| 6 | + |
| 7 | +type |
| 8 | + TItemBase = record |
| 9 | + Symbol: Char; |
| 10 | + Name: string; |
| 11 | + MaxDurability: Byte; |
| 12 | + Color: Cardinal; |
| 13 | + Deep: TDeepEnum; |
| 14 | + end; |
| 15 | + |
| 16 | +const |
| 17 | + ItemCount = 6; |
| 18 | + // |
| 19 | + itGold = 0; |
| 20 | + |
| 21 | +const |
| 22 | + ItemBase: array [0..ItemCount - 1] of TItemBase = ( |
| 23 | + // All |
| 24 | + (Symbol: '$'; Name: 'Gold'; MaxDurability: 0; Color: clYellow; Deep: deDarkWood; ), |
| 25 | + // Dark Wood |
| 26 | + (Symbol: '/'; Name: 'Item'; MaxDurability: 0; Color: clYellow; Deep: deDarkWood; ), |
| 27 | + // Gray Cave |
| 28 | + (Symbol: '/'; Name: 'Item'; MaxDurability: 0; Color: clYellow; Deep: deGrayCave; ), |
| 29 | + // Deep Cave |
| 30 | + (Symbol: '/'; Name: 'Item'; MaxDurability: 0; Color: clYellow; Deep: deDeepCave; ), |
| 31 | + // Blood Cave |
| 32 | + (Symbol: '/'; Name: 'Item'; MaxDurability: 0; Color: clYellow; Deep: deBloodCave; ), |
| 33 | + // Dungeon of Doom |
| 34 | + (Symbol: '/'; Name: 'Item'; MaxDurability: 0; Color: clYellow; Deep: deDungeonOfDoom;) |
| 35 | + ); |
| 36 | + |
| 37 | +type |
| 38 | + TItems = class(TObject) |
| 39 | + private |
| 40 | + |
| 41 | + public |
| 42 | + constructor Create; |
| 43 | + destructor Destroy; override; |
| 44 | + procedure Render(AX, AY: Byte); |
| 45 | + procedure Add(ADeep: TDeepEnum); |
| 46 | + end; |
| 47 | + |
| 48 | +var |
| 49 | + Items: TItems = nil; |
| 50 | + |
5 | 51 | implementation |
6 | 52 |
|
| 53 | +uses Math, uTerminal, uPlayer; |
| 54 | + |
| 55 | +{ TItems } |
| 56 | + |
| 57 | +procedure TItems.Add(ADeep: TDeepEnum); |
| 58 | +var |
| 59 | + ID, FX, FY: Byte; |
| 60 | + FItem: Item; |
| 61 | + D: Integer; |
| 62 | +begin |
| 63 | + repeat |
| 64 | + ID := Math.RandomRange(0, ItemCount); |
| 65 | + FX := Math.RandomRange(0, High(Byte)); |
| 66 | + FY := Math.RandomRange(0, High(Byte)); |
| 67 | + until (Map.GetTileEnum(FX, FY, ADeep) in SpawnTiles) |
| 68 | + and ((ID <= itGold) or (ItemBase[ID].Deep = ADeep)); |
| 69 | + FItem.MapID := Ord(ADeep); |
| 70 | + FItem.ItemID := ID; |
| 71 | + FItem.X := FX; |
| 72 | + FItem.Y := FY; |
| 73 | + case FItem.ItemID of |
| 74 | + itGold: // Gold |
| 75 | + begin |
| 76 | + FItem.Stack := 1000; |
| 77 | + FItem.Amount := Math.RandomRange(0, 25) + 1; |
| 78 | + end; |
| 79 | + else |
| 80 | + begin |
| 81 | + FItem.Stack := 1; |
| 82 | + FItem.Amount := 1; |
| 83 | + end; |
| 84 | + end; |
| 85 | + if (FItem.Stack = 1) then |
| 86 | + begin |
| 87 | + D := ItemBase[ID].MaxDurability; |
| 88 | + FItem.Durability := Math.RandomRange(D div 5, D) + 1; |
| 89 | + end; |
| 90 | + Items_Dungeon_AppendItem(FItem); |
| 91 | +end; |
| 92 | + |
| 93 | +constructor TItems.Create; |
| 94 | +begin |
| 95 | + Items_Open; |
| 96 | +end; |
| 97 | + |
| 98 | +destructor TItems.Destroy; |
| 99 | +begin |
| 100 | + Items_Close; |
| 101 | + inherited; |
| 102 | +end; |
| 103 | + |
| 104 | +procedure TItems.Render(AX, AY: Byte); |
| 105 | +var |
| 106 | + I, Count: Integer; |
| 107 | + FItem: Item; |
| 108 | + MapID: Byte; |
| 109 | +begin |
| 110 | + MapID := Ord(Map.Deep); |
| 111 | + Count := Items_Dungeon_GetMapCount(MapID); |
| 112 | + for I := Count - 1 downto 0 do |
| 113 | + begin |
| 114 | + FItem := Items_Dungeon_GetMapItem(MapID, I); |
| 115 | + if not Map.InView(FItem.X, FItem.Y) |
| 116 | + or (not WizardMode and not Map.GetFOV(FItem.X, FItem.Y)) then Continue; |
| 117 | + Terminal.Print(FItem.X - Player.X + AX + View.Left, |
| 118 | + FItem.Y - Player.Y + AY + View.Top, ItemBase[FItem.ItemID].Symbol, |
| 119 | + ItemBase[FItem.ItemID].Color); |
| 120 | + end; |
| 121 | +end; |
| 122 | + |
| 123 | +initialization |
| 124 | + Items := TItems.Create; |
| 125 | + |
| 126 | +finalization |
| 127 | + Items.Free; |
| 128 | + Items := nil; |
| 129 | + |
7 | 130 | end. |
0 commit comments