initial commit
This commit is contained in:
90
scripts/mob_scripts/goblin_ai.py
Executable file
90
scripts/mob_scripts/goblin_ai.py
Executable file
@@ -0,0 +1,90 @@
|
||||
######################################################################
|
||||
# NOTE: This was the first mob I wrote in Python / Jython. #
|
||||
# It is excessively commented to provide a reference for other #
|
||||
# Mobs to be written. #
|
||||
# #
|
||||
# 88 88 88 #
|
||||
# 88 88 "" #
|
||||
# 88 88 #
|
||||
# ,adPPYb,d8 ,adPPYba, 88,dPPYba, 88 88 8b,dPPYba, #
|
||||
# a8" `Y88 a8" "8a 88P' "8a 88 88 88P' `"8a #
|
||||
# 8b 88 8b d8 88 d8 88 88 88 88 #
|
||||
# "8a, ,d88 "8a, ,a8" 88b, ,a8" 88 88 88 88 #
|
||||
# `"YbbdP"Y8 `"YbbdP"' 8Y"Ybbd8"' 88 88 88 88 #
|
||||
# aa, ,88 #
|
||||
# "Y8bbdP" #
|
||||
# #
|
||||
######################################################################
|
||||
|
||||
def __goblin_tick__(g):
|
||||
### RUN ALL THE ANIMATIONS
|
||||
g.runAnimations()
|
||||
|
||||
# IF NOT ALIVE, DO AFTER DEATH
|
||||
if not g.alive():
|
||||
__goblin_after_death__(g)
|
||||
return
|
||||
|
||||
# DISCOVER
|
||||
if not g.getDiscoveredStatus(): return
|
||||
|
||||
## IF HEALTH IS ABOVE THE MAX HEALTH, CLAMP
|
||||
g.normalizeHealth()
|
||||
|
||||
### IF THE GET HIT TIMER IS POSITIVE, START DECREMENTING IT
|
||||
g.getHitClock()
|
||||
|
||||
### COLLISION
|
||||
g.collision()
|
||||
|
||||
### POSITION
|
||||
g.updatePosition()
|
||||
|
||||
## IDLE ANIMATIONS (idles, walks)
|
||||
__goblin_idle__(g)
|
||||
|
||||
### IF IS ALREADY FIGHTING, THEN TICK HIS ATTACK SEQUENCE WITH RUNNING SPEED
|
||||
if g.inCombat: g.attackSequence(g.runningSpeed)
|
||||
## IF NOT ALREADY FIGHTING, AND AGGRO-RADIUS INTERSECTS THE PLAYER, START FIGHTING
|
||||
elif Utils.intersects(g.center, g.aggroRadius, Player.center): g.startAttackSequence()
|
||||
|
||||
# run bug fixes
|
||||
g.allBugFixes()
|
||||
|
||||
def __goblin_idle__(g):
|
||||
## ONLY WORK IF *NOT* IN COMBAT / RUNNING AWAY
|
||||
if g.collided or g.runningAway or g.inCombat: return
|
||||
|
||||
## SUBTRACT FROM ANIMATION TIMER IF DOING IDLE ANIMATION
|
||||
if g.currentAnimation != ANIMATION.idleWalk: g.idleAnimationTimer -= 1
|
||||
|
||||
## SUBTRACT FROM IDLE WALK DISTANCE IF IDLE WALKING
|
||||
elif g.currentAnimation == ANIMATION.idleWalk: g.distanceToMove -= Utils.pythagoras(g.velX, g.velY)
|
||||
|
||||
## IF WALKING AROUND, AND HIS DISTANCE IS UP:
|
||||
if g.distanceToMove <= 0 and g.currentAnimation == ANIMATION.idleWalk:
|
||||
### CHANCE OF CONTINUING ON WALKING INSTEAD OF IDLING
|
||||
if Utils.rand.nextInt(8) == 0: g.idleMove(g.walkingSpeed)
|
||||
else: #### ELSE SET HIM GOING TO A RANDOM IDLE ANIMATION
|
||||
g.idleAnimationTimer = Utils.rand.nextInt(200) + 100
|
||||
g.velX = g.velY = 0
|
||||
if Utils.COIN_FLIP(): g.currentAnimation = ANIMATION.idle1
|
||||
else: g.currentAnimation = ANIMATION.idle2
|
||||
|
||||
### IF ANIMATION DOES NOT EQUAL IDLE WALK AND THE IDLE ANIMATION TIMER IS UP, SET HIM WALKING
|
||||
if g.currentAnimation != ANIMATION.idleWalk and g.idleAnimationTimer <= 0: g.idleMove(g.walkingSpeed)
|
||||
|
||||
### IF GOBLIN IS OUTSIDE OF HIS HOME BUT ISNT COMBAT OR WALKING
|
||||
if not g.home.contains(g.center):
|
||||
g.currentAnimation = ANIMATION.idleWalk ## some mobs may have a run animation
|
||||
## IF SO FAR AWAY, RUN HOME, ELSE JUST WALK HOME
|
||||
if(g.center.distance(g.home.center) > 5000): g.goHome(g.runningSpeed)
|
||||
else: g.goHome(g.walkingSpeed)
|
||||
|
||||
def __goblin_after_death__(g):
|
||||
## SUBTRACT FROM DESTROYING TIMER
|
||||
g.destroyingTimer -= 1
|
||||
|
||||
## IF THE TIMER IS UP, DESTROY!
|
||||
if g.destroyingTimer < 0: g.destroy()
|
||||
|
||||
124
scripts/other/inventory.py
Executable file
124
scripts/other/inventory.py
Executable file
@@ -0,0 +1,124 @@
|
||||
##### NOTE, ALWAYS CALL ' CHANGE SETTINGS ' AFTER EVERY METHOD
|
||||
##### THIS HELPS FIX THE BUGGY GUI SYSTEM
|
||||
|
||||
##### NOTE: YOU NEED TO IMPORT * FROM ItemIDs INTERFACE!
|
||||
|
||||
####################################################
|
||||
# _____ _ #
|
||||
# |_ _| | | #
|
||||
# | | _ ____ _____ _ __ | |_ ___ _ __ _ _ #
|
||||
# | | | '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | #
|
||||
# _| |_| | | \ V / __/ | | | || (_) | | | |_| | #
|
||||
# |_____|_| |_|\_/ \___|_| |_|\__\___/|_| \__, | #
|
||||
# __/ | #
|
||||
# |___/ #
|
||||
####################################################
|
||||
|
||||
|
||||
############### ADDING AND REMOVING ITEMS #######################
|
||||
def drop_item(itemId, quantity, durability, slotNumber):
|
||||
#Make sure items can be dropped:
|
||||
for i in Player.inventorySlots:
|
||||
if i.itemId == itemId and i.quantity <= 0: return
|
||||
|
||||
#Create new dropped item to be shown on ground
|
||||
DroppedItem.dropItemsWithOffsetAsStack(itemId, quantity, 10, Player.center.x, Player.center.y, durability)
|
||||
|
||||
# Remove the item from the inventory
|
||||
remove_item_with_slot_number(itemId, quantity, slotNumber)
|
||||
|
||||
Inventory.changeSettings()
|
||||
|
||||
def remove_item(itemId, quantity):
|
||||
for slot in Player.inventorySlots:
|
||||
if slot.itemId == itemId:
|
||||
temp = slot.quantity
|
||||
slot.quantity -= quantity
|
||||
quantity -= temp
|
||||
slot.mouseClicked = 0
|
||||
|
||||
if slot.quantity <= 0: slot.itemId = slot.quantity = slot.durability = 0
|
||||
|
||||
# if the amount of things to remove has been satisfied
|
||||
if quantity <= 0: break
|
||||
Inventory.changeSettings()
|
||||
|
||||
def remove_item_with_slot_number(itemId, quantity, slotNumber):
|
||||
for i in Player.inventorySlots:
|
||||
if i.slotNumber == slotNumber:
|
||||
if i.itemId == itemId:
|
||||
i.quantity -= quantity
|
||||
i.mouseClicked = False
|
||||
if i.quantity <= 0: i.itemId = i.quantity = i.durability = 0
|
||||
break
|
||||
|
||||
Inventory.changeSettings()
|
||||
|
||||
def remove_equipment(itemId, quantity, slotNumber):
|
||||
for i in Player.equipmentSlots:
|
||||
if i.slotNumber == slotNumber:
|
||||
if i.itemId == itemId:
|
||||
i.quantity -= quantity
|
||||
|
||||
#### FOR LIGHTS, TORCHES etc
|
||||
if i.itemId == TORCH: Player.playerLights.remove(Player.torchLight)
|
||||
|
||||
if i.quantity <= 0: i.itemId = i.quantity = 0
|
||||
|
||||
i.durability = 0
|
||||
i.mouseClicked = False
|
||||
break
|
||||
|
||||
Inventory.changeSettings()
|
||||
|
||||
def add_item(itemId, quantity, durability):
|
||||
# CANT ADD ITEM IF THE INVEN IS FULL
|
||||
if inventory_is_full(itemId, quantity): return
|
||||
|
||||
# IF THE ITEM IS STACKABLE, RUN THIS LOOP
|
||||
if InvenHelper.isStackable(itemId):
|
||||
for i in Player.inventorySlots:
|
||||
if i.itemId == itemId and (i.quantity + quantity) <= InvenHelper.getStackableAmount(itemId):
|
||||
i.mouseClicked = False
|
||||
i.quantity += quantity
|
||||
Inventory.changeSettings()
|
||||
return
|
||||
|
||||
# IF THE ITEM IS NOT STACKABLE, OR FAILED THE ABOVE LOOP, RUN THIS LOOP
|
||||
for i in Player.inventorySlots:
|
||||
if(i.itemId == 0):
|
||||
i.mouseClicked = False
|
||||
i.itemId = itemId
|
||||
i.quantity = quantity
|
||||
i.durability = durability
|
||||
i.equippable = InvenHelper.isEquippable(itemId)
|
||||
Inventory.changeSettings()
|
||||
return
|
||||
|
||||
############### END ADDING AND REMOVING ITEMS #################################################################
|
||||
|
||||
################ MISC ##################################################################################
|
||||
|
||||
def inventory_is_full(itemId, quantity):
|
||||
if InvenHelper.isStackable(itemId): # IF ITEM IS STACKABLE, RUN THIS LOOP
|
||||
for slot in Player.inventorySlots:
|
||||
# CHECK IF THE (QUANTITY + THE ADDED QUANTITY) IS <= THE MAX QUANTITY
|
||||
WOULD_BE_QUANTITY = slot.quantity + quantity
|
||||
if slot.itemId == itemId and WOULD_BE_QUANTITY <= InvenHelper.getStackableAmount(itemId): return False
|
||||
|
||||
# IF IT IS NOT STACKABLE, OR THE ITEM FAILED THE FIRST LOOP, RUN THIS LOOP
|
||||
for slot in Player.inventorySlots:
|
||||
if slot.itemId == NULL_ITEM: return False
|
||||
|
||||
# IF NONE OF THE ABOVE CONDITIONS COULD BE MET, THE INVENTORY MUST BE FULL
|
||||
return True
|
||||
|
||||
def inventory_contains(itemId, quantity):
|
||||
count = 0
|
||||
for slot in Player.inventorySlots:
|
||||
if slot.itemId == itemId: count += slot.quantity
|
||||
return count >= quantity
|
||||
|
||||
############## END MISC #######################################################################################
|
||||
|
||||
|
||||
Reference in New Issue
Block a user