| Mirage Source http://web.miragesource.net/forums/ |
|
| Random Coding http://web.miragesource.net/forums/viewtopic.php?f=193&t=4498 |
Page 1 of 1 |
| Author: | Jacob [ Fri Oct 03, 2008 8:29 pm ] |
| Post subject: | Random Coding |
ItemRec Added the array to hold any values for modified stats / vitals. Code: Type ItemRec Name As String * NAME_LENGTH Pic As Integer Type As Byte Data1 As Integer Data2 As Integer Data3 As Integer ModVital(1 To Vitals.Vital_Count - 1) As Long ModStat(1 To Stats.Stat_Count - 1) As Long End Type The following function will go though all your equipment and add up any stats plus the base stat value. Code: '*************************************** ' Calculate current modified stats '*************************************** Public Function Current_ModStat(ByVal Index As Long, ByVal Stat As Stats) As Long Dim i As Long, ItemNum As Long Current_ModStat = Current_Stat(Index, Stat) For i = 1 To Equipment.Equipment_Count - 1 If Current_EquipmentSlot(Index, i) > 0 Then Current_ModStat = Current_ModStat + Item(Current_InvItemNum(Index, Current_EquipmentSlot(Index, i))).ModStat(Stat) End If Next End Function The following function will go though all your equipment and add up any vitals plus the base vital value. Code: '*************************************** ' Calculate current modified vitals '*************************************** Public Function Current_ModVital(ByVal Index As Long, ByVal Vital As Vitals) As Long Dim i As Long, ItemNum As Long Current_ModVital = 0 For i = 1 To Equipment.Equipment_Count - 1 If Current_EquipmentSlot(Index, i) > 0 Then Current_ModVital = Current_ModVital + Item(Current_InvItemNum(Index, Current_EquipmentSlot(Index, i))).ModVital(Vital) End If Next End Function Just using the new modStat and modVital to calculate the max vitals. Code: '*************************************** ' Calculate Max Vital '*************************************** Public Function Current_MaxVital(ByVal Index As Long, ByVal Vital As Vitals) As Long Select Case Vital Case HP Current_MaxVital = (Current_Level(Index) + Int(Current_ModStat(Index, Stats.Strength) / 2) + Class(Current_Class(Index)).Stat(Stats.Strength)) * 2 Case MP Current_MaxVital = (Current_Level(Index) + Int(Current_ModStat(Index, Stats.Magic) / 2) + Class(Current_Class(Index)).Stat(Stats.Magic)) * 2 Case SP Current_MaxVital = (Current_Level(Index) + Int(Current_ModStat(Index, Stats.Speed) / 2) + Class(Current_Class(Index)).Stat(Stats.Speed)) * 2 End Select Current_MaxVital = Current_MaxVital + Current_ModVital(Index, Vital) End Function Just using the new modStat and modVital to calculate the max vitals. Code: '*************************************** ' Calculate base damage '*************************************** Public Function Current_Damage(ByVal Index As Long) As Long Current_Damage = 0 ' Check for subscript out of range If IsPlaying(Index) = False Or Index <= 0 Or Index > MAX_PLAYERS Then Exit Function End If Current_Damage = Int(Current_ModStat(Index, Stats.Strength) / 2) If Current_Damage <= 0 Then Current_Damage = 1 End If If Current_EquipmentSlot(Index, Weapon) > 0 Then Current_Damage = Current_Damage + Item(Current_InvItemNum(Index, Current_EquipmentSlot(Index, Weapon))).Data2 End If End Function You'll have to change "Current_" to "GetPlayer". I was just messing around on how to do stats on equipment. |
|
| Author: | Jacob [ Sun Oct 05, 2008 1:10 am ] |
| Post subject: | Re: Random Coding |
Just messing around again. Code: Type PositionRec Map As Long X As Byte Y As Byte End Type Code: Type PlayerRec ' General Name As String * NAME_LENGTH Sex As Byte Class As Byte Sprite As Integer Level As Byte Exp As Long Access As Byte PK As Byte ' Vitals Vital(1 To Vitals.Vital_Count - 1) As Long ' Stats Stat(1 To Stats.Stat_Count - 1) As Byte POINTS As Byte ' Worn equipment Equipment(1 To Equipment.Equipment_Count - 1) As Byte ' Inventory Inv(1 To MAX_INV) As PlayerInvRec Spell(1 To MAX_PLAYER_SPELLS) As Byte ' Position Position As PositionRec Bound As PositionRec ' Current Direction Dir As Byte End Type Code: Public Function Current_Position(ByVal Index As Long) As PositionRec Current_Position = Player(Index).Char(Current_CharNum(Index)).Position End Function Sub Update_Position(ByVal Index As Long, ByRef NewPosition As PositionRec) Player(Index).Char(Current_CharNum(Index)).Position = NewPosition End Sub Code: Public Function Current_Bound(ByVal Index As Long) As PositionRec Current_Bound = Player(Index).Char(Current_CharNum(Index)).Bound End Function Sub Update_Bound(ByVal Index As Long, ByRef NewBound As PositionRec) Player(Index).Char(Current_CharNum(Index)).Bound = NewBound End Sub Code: Sub PlayerWarpPosition(ByVal Index As Long, ByRef NewPosition As PositionRec) Dim ShopNum As Long, OldMap As Long ' Check for subscript out of range If IsPlaying(Index) = False Or NewPosition.Map <= 0 Or NewPosition.Map > MAX_MAPS Then Exit Sub End If ' Check if there was an npc on the map the player is leaving, and if so say goodbye ShopNum = Map(Current_Map(Index)).Shop If ShopNum > 0 Then If LenB(Trim$(Shop(ShopNum).LeaveSay)) > 0 Then Call PlayerMsg(Index, Trim$(Shop(ShopNum).Name) & " says, '" & Trim$(Shop(ShopNum).LeaveSay) & "'", SayColor) End If End If ' Save old map to send erase player data to OldMap = Current_Map(Index) Call SendLeaveMap(Index, OldMap) Update_Position Index, NewPosition ' Check if there is an npc on the map and say hello if so ShopNum = Map(Current_Map(Index)).Shop If ShopNum > 0 Then If LenB(Trim$(Shop(ShopNum).JoinSay)) > 0 Then Call PlayerMsg(Index, Trim$(Shop(ShopNum).Name) & " says, '" & Trim$(Shop(ShopNum).JoinSay) & "'", SayColor) End If End If ' Now we check if there were any players left on the map the player just left, and if not stop processing npcs If GetTotalMapPlayers(OldMap) = 0 Then PlayersOnMap(OldMap) = NO End If ' Sets it so we know to process npcs on the map PlayersOnMap(NewPosition.Map) = YES TempPlayer(Index).GettingMap = YES Call SendDataTo(Index, SCheckForMap & SEP_CHAR & NewPosition.Map & SEP_CHAR & Map(NewPosition.Map).Revision & END_CHAR) End Sub Code: Sub PlayerWarp(ByVal Index As Long, ByVal MapNum As Long, ByVal X As Long, ByVal Y As Long) Dim ShopNum As Long, OldMap As Long ' Check for subscript out of range If IsPlaying(Index) = False Or MapNum <= 0 Or MapNum > MAX_MAPS Then Exit Sub End If ' Check if there was an npc on the map the player is leaving, and if so say goodbye ShopNum = Map(Current_Map(Index)).Shop If ShopNum > 0 Then If LenB(Trim$(Shop(ShopNum).LeaveSay)) > 0 Then Call PlayerMsg(Index, Trim$(Shop(ShopNum).Name) & " says, '" & Trim$(Shop(ShopNum).LeaveSay) & "'", SayColor) End If End If ' Save old map to send erase player data to OldMap = Current_Map(Index) Call SendLeaveMap(Index, OldMap) Update_Map Index, MapNum Update_X Index, X Update_Y Index, Y ' Check if there is an npc on the map and say hello if so ShopNum = Map(Current_Map(Index)).Shop If ShopNum > 0 Then If LenB(Trim$(Shop(ShopNum).JoinSay)) > 0 Then Call PlayerMsg(Index, Trim$(Shop(ShopNum).Name) & " says, '" & Trim$(Shop(ShopNum).JoinSay) & "'", SayColor) End If End If ' Now we check if there were any players left on the map the player just left, and if not stop processing npcs If GetTotalMapPlayers(OldMap) = 0 Then PlayersOnMap(OldMap) = NO End If ' Sets it so we know to process npcs on the map PlayersOnMap(MapNum) = YES TempPlayer(Index).GettingMap = YES Call SendDataTo(Index, SCheckForMap & SEP_CHAR & MapNum & SEP_CHAR & Map(MapNum).Revision & END_CHAR) End Sub Usage: Current_Position(Index).Map Current_Position(Index).X Current_Position(Index).Y |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|