Adds simple framework for learnable crafting recipes (#43296)

* Adds simple framework for learnable crafting recipes

* whoops

* Moves teach/check functions to mind

* Code golf

* I just moved these around but fine.

Co-Authored-By: AnturK <AnturK@users.noreply.github.com>
This commit is contained in:
AnturK
2019-03-29 16:55:29 +01:00
committed by yogstation13-bot
parent 3bb3846591
commit 45859aa502
4 changed files with 107 additions and 75 deletions

View File

@@ -64,6 +64,8 @@
var/force_escaped = FALSE // Set by Into The Sunset command of the shuttle manipulator var/force_escaped = FALSE // Set by Into The Sunset command of the shuttle manipulator
var/list/learned_recipes //List of learned recipe TYPES.
/datum/mind/New(var/key) /datum/mind/New(var/key)
src.key = key src.key = key
soulOwner = src soulOwner = src

View File

@@ -13,21 +13,52 @@
/obj/item/book/granter/proc/turn_page(mob/user) /obj/item/book/granter/proc/turn_page(mob/user)
playsound(user, pick('sound/effects/pageturn1.ogg','sound/effects/pageturn2.ogg','sound/effects/pageturn3.ogg'), 30, 1) playsound(user, pick('sound/effects/pageturn1.ogg','sound/effects/pageturn2.ogg','sound/effects/pageturn3.ogg'), 30, 1)
if(do_after(user,50, user)) if(do_after(user,50, user))
to_chat(user, "<span class='notice'>[pick(remarks)]</span>") if(remarks.len)
to_chat(user, "<span class='notice'>[pick(remarks)]</span>")
else
to_chat(user, "<span class='notice'>You keep reading...</span>")
return TRUE return TRUE
return FALSE return FALSE
/obj/item/book/granter/proc/recoil(mob/user) //nothing so some books can just return /obj/item/book/granter/proc/recoil(mob/user) //nothing so some books can just return
/obj/item/book/granter/proc/already_known(mob/user)
return FALSE
/obj/item/book/granter/proc/on_reading_start(mob/user)
to_chat(user, "<span class='notice'>You start reading [name]...</span>")
/obj/item/book/granter/proc/on_reading_stopped(mob/user)
to_chat(user, "<span class='notice'>You stop reading...</span>")
/obj/item/book/granter/proc/on_reading_finished(mob/user)
to_chat(user, "<span class='notice'>You finish reading [name]!</span>")
/obj/item/book/granter/proc/onlearned(mob/user) /obj/item/book/granter/proc/onlearned(mob/user)
used = TRUE used = TRUE
/obj/item/book/granter/attack_self(mob/user) /obj/item/book/granter/attack_self(mob/user)
if(reading) if(reading)
to_chat(user, "<span class='warning'>You're already reading this!</span>") to_chat(user, "<span class='warning'>You're already reading this!</span>")
return FALSE return FALSE
if(!user.can_read(src)) if(!user.can_read(src))
return FALSE return FALSE
if(already_known(user))
return FALSE
if(used && oneuse)
recoil(user)
else
on_reading_start(user)
reading = TRUE
for(var/i=1, i<=pages_to_mastery, i++)
if(!turn_page(user))
on_reading_stopped()
reading = FALSE
return
if(do_after(user,50, user))
on_reading_finished(user)
reading = FALSE
return TRUE return TRUE
///ACTION BUTTONS/// ///ACTION BUTTONS///
@@ -36,33 +67,23 @@
var/granted_action var/granted_action
var/actionname = "catching bugs" //might not seem needed but this makes it so you can safely name action buttons toggle this or that without it fucking up the granter, also caps var/actionname = "catching bugs" //might not seem needed but this makes it so you can safely name action buttons toggle this or that without it fucking up the granter, also caps
/obj/item/book/granter/action/attack_self(mob/user) /obj/item/book/granter/action/already_known(mob/user)
. = ..()
if(!.)
return
if(!granted_action) if(!granted_action)
return return TRUE
var/datum/action/G = new granted_action
for(var/datum/action/A in user.actions) for(var/datum/action/A in user.actions)
if(A.type == G.type) if(A.type == granted_action)
to_chat(user, "<span class='notice'>You already know all about [actionname].</span>") to_chat(user, "<span class='notice'>You already know all about [actionname].</span>")
qdel(G) return TRUE
return return FALSE
if(used == TRUE && oneuse == TRUE)
recoil(user) /obj/item/book/granter/action/on_reading_start(mob/user)
else to_chat(user, "<span class='notice'>You start reading about [actionname]...</span>")
to_chat(user, "<span class='notice'>You start reading about [actionname]...</span>")
reading = TRUE /obj/item/book/granter/action/on_reading_finished(mob/user)
for(var/i=1, i<=pages_to_mastery, i++) to_chat(user, "<span class='notice'>You feel like you've got a good handle on [actionname]!</span>")
if(!turn_page(user)) var/datum/action/G = new granted_action
to_chat(user, "<span class='notice'>You stop reading...</span>") G.Grant(user)
reading = FALSE onlearned(user)
qdel(G)
return
if(do_after(user,50, user))
to_chat(user, "<span class='notice'>You feel like you've got a good handle on [actionname]!</span>")
G.Grant(user)
reading = FALSE
/obj/item/book/granter/action/origami /obj/item/book/granter/action/origami
granted_action = /datum/action/innate/origami granted_action = /datum/action/innate/origami
@@ -97,38 +118,28 @@
var/spell var/spell
var/spellname = "conjure bugs" var/spellname = "conjure bugs"
/obj/item/book/granter/spell/attack_self(mob/user) /obj/item/book/granter/spell/already_known(mob/user)
. = ..()
if(!.)
return
if(!spell) if(!spell)
return return TRUE
var/obj/effect/proc_holder/spell/S = new spell
for(var/obj/effect/proc_holder/spell/knownspell in user.mind.spell_list) for(var/obj/effect/proc_holder/spell/knownspell in user.mind.spell_list)
if(knownspell.type == S.type) if(knownspell.type == spell)
if(user.mind) if(user.mind)
if(iswizard(user)) if(iswizard(user))
to_chat(user,"<span class='notice'>You're already far more versed in this spell than this flimsy how-to book can provide.</span>") to_chat(user,"<span class='notice'>You're already far more versed in this spell than this flimsy how-to book can provide.</span>")
else else
to_chat(user,"<span class='notice'>You've already read this one.</span>") to_chat(user,"<span class='notice'>You've already read this one.</span>")
return FALSE return TRUE
if(used == TRUE && oneuse == TRUE) return FALSE
recoil(user)
else /obj/item/book/granter/spell/on_reading_start(mob/user)
to_chat(user, "<span class='notice'>You start reading about casting [spellname]...</span>") to_chat(user, "<span class='notice'>You start reading about casting [spellname]...</span>")
reading = TRUE
for(var/i=1, i<=pages_to_mastery, i++) /obj/item/book/granter/spell/on_reading_finished(mob/user)
if(!turn_page(user)) to_chat(user, "<span class='notice'>You feel like you've experienced enough to cast [spellname]!</span>")
to_chat(user, "<span class='notice'>You stop reading...</span>") var/obj/effect/proc_holder/spell/S = new spell
reading = FALSE user.mind.AddSpell(S)
qdel(S) user.log_message("learned the spell [spellname] ([S])", LOG_ATTACK, color="orange")
return FALSE onlearned(user)
if(do_after(user,50, user))
to_chat(user, "<span class='notice'>You feel like you've experienced enough to cast [spellname]!</span>")
user.mind.AddSpell(S)
user.log_message("learned the spell [spellname] ([S])", LOG_ATTACK, color="orange")
onlearned(user)
reading = FALSE
/obj/item/book/granter/spell/recoil(mob/user) /obj/item/book/granter/spell/recoil(mob/user)
user.visible_message("<span class='warning'>[src] glows in a black light!</span>") user.visible_message("<span class='warning'>[src] glows in a black light!</span>")
@@ -305,33 +316,25 @@
var/martialname = "bug jitsu" var/martialname = "bug jitsu"
var/greet = "You feel like you have mastered the art in breaking code. Nice work, jackass." var/greet = "You feel like you have mastered the art in breaking code. Nice work, jackass."
/obj/item/book/granter/martial/attack_self(mob/user)
. = ..() /obj/item/book/granter/martial/already_known(mob/user)
if(!.)
return
if(!martial) if(!martial)
return return TRUE
var/datum/martial_art/MA = new martial var/datum/martial_art/MA = martial
if(user.mind.has_martialart(MA.id)) if(user.mind.has_martialart(initial(MA.id)))
to_chat(user,"<span class='warning'>You already know [martialname]!</span>") to_chat(user,"<span class='warning'>You already know [martialname]!</span>")
return return TRUE
if(used == TRUE && oneuse == TRUE) return FALSE
recoil(user)
else /obj/item/book/granter/martial/on_reading_start(mob/user)
to_chat(user, "<span class='notice'>You start reading about [martialname]...</span>") to_chat(user, "<span class='notice'>You start reading about [martialname]...</span>")
reading = TRUE
for(var/i=1, i<=pages_to_mastery, i++) /obj/item/book/granter/martial/on_reading_finished(mob/user)
if(!turn_page(user)) to_chat(user, "[greet]")
to_chat(user, "<span class='notice'>You stop reading...</span>") var/datum/martial_art/MA = new martial
reading = FALSE MA.teach(user)
qdel(MA) user.log_message("learned the martial art [martialname] ([MA])", LOG_ATTACK, color="orange")
return onlearned(user)
if(do_after(user,50, user))
to_chat(user, "[greet]")
MA.teach(user)
user.log_message("learned the martial art [martialname] ([MA])", LOG_ATTACK, color="orange")
onlearned(user)
reading = FALSE
/obj/item/book/granter/martial/cqc /obj/item/book/granter/martial/cqc
martial = /datum/martial_art/cqc martial = /datum/martial_art/cqc
@@ -392,3 +395,18 @@
icon_state = "blankscroll" icon_state = "blankscroll"
// I did not include mushpunch's grant, it is not a book and the item does it just fine. // I did not include mushpunch's grant, it is not a book and the item does it just fine.
//Crafting Recipe books
/obj/item/book/granter/crafting_recipe
var/list/crafting_recipe_types = list()
/obj/item/book/granter/crafting_recipe/on_reading_finished(mob/user)
. = ..()
if(!user.mind)
return
for(var/crafting_recipe_type in crafting_recipe_types)
var/datum/crafting_recipe/R = crafting_recipe_type
user.mind.teach_crafting_recipe(crafting_recipe_type)
to_chat(user,"<span class='notice'>You learned how to make [initial(R.name)].</span>")

View File

@@ -317,6 +317,10 @@
var/list/cant_craft = list() var/list/cant_craft = list()
for(var/rec in GLOB.crafting_recipes) for(var/rec in GLOB.crafting_recipes)
var/datum/crafting_recipe/R = rec var/datum/crafting_recipe/R = rec
if(!R.always_availible && !(R.type in user?.mind?.learned_recipes)) //User doesn't actually know how to make this.
continue
if((R.category != cur_category) || (R.subcategory != cur_subcategory)) if((R.category != cur_category) || (R.subcategory != cur_subcategory))
continue continue
if(check_contents(R, surroundings)) if(check_contents(R, surroundings))
@@ -431,3 +435,10 @@
data["tool_text"] = tool_text data["tool_text"] = tool_text
return data return data
//Mind helpers
/datum/mind/proc/teach_crafting_recipe(R)
if(!learned_recipes)
learned_recipes = list()
learned_recipes |= R

View File

@@ -10,6 +10,7 @@
var/chem_catalysts[] = list() //like tools but for reagents var/chem_catalysts[] = list() //like tools but for reagents
var/category = CAT_NONE //where it shows up in the crafting UI var/category = CAT_NONE //where it shows up in the crafting UI
var/subcategory = CAT_NONE var/subcategory = CAT_NONE
var/always_availible = TRUE //Set to FALSE if it needs to be learned first.
/datum/crafting_recipe/pin_removal /datum/crafting_recipe/pin_removal
name = "Pin Removal" name = "Pin Removal"